How to use centre difference method to make the equation semi descrete in terms of time - pde

enter image description here
where u : Ω → R
n is the displacement vector field, C is the stiffness tensor of
the elastic medium, (u) is the linearized strain tensor of displacement, ρ is the
mass density, and f is an external body force.

Related

Calculating Displacement based on the compass direction

I need some help with programming the calculation of displacement. Given the distance the object has moved in the XY plane, and the yaw (heading) of the object, I'd like to calculate the displacement of the object. For example, the object moved 5m North and 2m East.
The data I have is the distance it travels in the XY plane (X distance and Y distance) and the heading of the device which is determined by the direction of X. I know how to calculate it on paper but I am having trouble to program it.
I've attached two examples that shows how I obtained the calculations. The black dot is the displacement of the object. In the 1st example, the X-distance travelled is 3 meters while the Y-distance is 4 meters and the heading of the X-axis is 70°. After calculating, I managed to get that it has travelled 2.733m South and 4.187m East. In example 2, it travel, the X-distance is -5m and the Y-distance is -12m, the heading is 160°. I calculated that the object travels 8.80m North and 9.566m East.
Example 1
Example 2
Assume you have your XY pane rotated by some angle Zp and have a 2D movement vector within that pane, let's say its direction rotated by Zv – what is total rotation of the vector, relative to the global orientation? Zp + Zv...
So all you need to do is applying the rotation Zp to the movement vector within XY-pane, i. e. apply a rotation matrix to the vector. This matrix for a rotation by z looks like:
cos(z) -sin(z)
sin(z) cos(z)
With our data above:
north = cos(Zp) * x - sin(Zp) * y
east = sin(Zp) * x + cos(Zp) * y
which gives, with your first sample data applied:
north = cos(70°) * 3 - sin(70°) * 4 ~ -2.7327
east = sin(70°) * 3 + cos(70°) * 4 ~ 4.1872
north = cos(160°) * -5 - sin(160°) * -12 ~ 8.8027
east = sin(160°) * -5 + cos(160°) * -12 ~ 9.5662
Corresponding pretty much to the values you calculated (note: negative movement to north is positive movement towards south...).
What you are doing is a conversion from polar to Cartesian coordinates. https://en.wikipedia.org/wiki/Polar_coordinate_system#Converting_between_polar_and_Cartesian_coordinates
If your Cartesian coordinates are not aligned to the polar axis, just compensate by adding the rotation angle to the polar argument.

Understanding Hadamard gate in depth

I know that a Hadamard gate is implemented by rotating around the axis (x + z )/ sqrt(2), but how can I compute the matrix obtained by rotation around this axis by π radians, and compare to a Hadamard gate matrix.
Thanks for your help.
Using H = (x + z)/ sqrt(2)
Find the rotation along x-axis (rx), and rotation along z-axis (rz), then multiply.

Three-dimensional array in R for netCDF

I need to create a three-dimensional array in R which contains the data of a raster with a resolution of 538x907 pixel. I have this raster for each hour in one month, so in January there are 744 raster files. I have to change some values by R and want to summarize them afterwards back to an array that can be processed by the package ncdf4. Therefor I need to create a three-dimensional array which looks like prectdata[1:538, 1:907, 1:744] (first and second for x and y dimension of the raster, third for time dimension). How do I have do concatenate the 744 raster matrices to a three-dimensioanl array for Package ncdf4?
The raster package has a function called as.array which should do just what you want:
library(raster)
# single raster
r <- raster(matrix(runif(538*907),nrow =538))
# stack them
rstack <- do.call(stack,lapply(1:744,function(x) r))
# structure
> rstack
class : RasterStack
dimensions : 538, 907, 487966, 744 (nrow, ncol, ncell, nlayers)
resolution : 0.001102536, 0.001858736 (x, y)
extent : 0, 1, 0, 1 (xmin, xmax, ymin, ymax)
coord. ref. : NA
# convert to array
arr <- as.array(rstack)
# check dimensions
> dim(arr)
[1] 538 907 744

inverse a number

As we go up the musical scale the note frequency increases;
#define A4 440 // These are the frequencies of the notes in herts
#define AS4 466
#define B4 494
#define C5 523
#define CS5 554
#define D5 587
I am generating the tones mechanically, I tell a step motor to step, delay, step, delay etc etc very quickly.
The longer the delay between steps, the lower the note. Is there some smart maths I could use to inverse the frequencies so as I climb up the scale the numbers come out lower and lower?
This way I could use the frequencies to help calculate the correct delay to generate a note.
So what you're saying is you want the numbers to represent the time between steps rather than a frequency?
440 Hz means 440 cycles/second. What you want is the number of seconds/cycle (i.e. time between steps). That's just 1 / <frequency>. That means all you have to do is define your values as 1/440, 1/466, etc. (or, if you want the values to be milliseconds, 1000/440, 1000/466 etc.)
If that is too fast (or doesn't match the actual notes), you can multiply each value by a scale factor and the relationships between the audible tones should remain the same.
For example, lets say that you empirically discover that for your machine to make an "A4" tone, the delay between steps is 10 milliseconds. To figure out the scale factor, solve for x:
x / 440 = 10
x = 4400
So define scale = 4400, and define each of your notes as scale / 440, scale / 466 etc.
Yes, that sounds possible! Let's have a look... (some of this you will know but I'll post it anyway)
In what's called an equal tempered scale, you can calculate Hertz values by multiplying by the twelfth root of two for every semitone you go up. There are 12 semitones in a whole octave, and multiplying by this value twelve times doubles the frequency, which raises the tone by an octave.
So, if you wanted to calculate descending semitone frequencies from e.g. A 440, you can calculate double x = pow(2.0, 1.0/12.0) (assuming C), and then repeatedly divide by that value (remember to do the divisions as doubles not ints :) ) and then you'll get your descending scale.
Aside: If you want to do a major scale rather than a chromatic (semitone) scale, this is the pattern of tones and semitones to use: (e.g. in C Major - using T for Tone, S for semitone)
C [T] D [T] E [S] F [T] G [T] A [T] B [S] C

Fastest approximative methods to convert YUV to RGBA?

I am looking for a fastest method to convert one YUV array into RGBA array. For example, given a YCbYCr array, which is a sequence of bytes:
YCbYCr = Luma0, Cb0, Luma1, Cr0, Luma2, ...
where 8-bit blue- and 8-bit red- difference chroma components are sampled with period 2, but 8-bit luma is sampled with period 1. For example:
image pixel (0,0) has luma0, Cr0 red-difference chroma, Cb0 blue-difference chroma
image pixel (0,1) has luma1, Cr0 red-difference chroma, Cb0 blue-difference chroma
image pixel (0,2) has luma2, Cr1 red-difference chroma, Cb1 blue-difference chroma
image pixel (0,3) has luma3, Cr1 red-difference chroma, Cb1 blue-difference chroma
etc.
RGBA array should be produced which is:
RGBA = R0, G0, B0, A0, R1, G1, ...
where all elements are unsigned chars and all bits of each A# are zero.
Luma component in YCbYCr is 0..255 unsigned char, Cb and Cr are -127..+126 signed chars. There is a standard approach --- matrix multiplication, but it's very slow for real time apps and it operates with floating point numbers. I am looking for a fast approximate numerical method.
The biggest single computational saving you're likely to get is simply by doing the computation in fixed-point rather than floating-point. It's likely to be an order of magnitude faster (at a guess).
You can also take advantage of the redundancy in the subsampled chroma contributions. Given that the full matrix multiply is of the form:
R a b c Y
G = d e f . Cb
B g h i Cr
You can compute the chroma partial sum half as often:
R' b c
G' = e f . Cb
B' h i Cr
and then simply add it to the luma contribution at the full output rate:
R R' a
G = G' + d . Y
B B' g

Resources