# Using MatrixOP on 3D wave

Thu, 12/12/2019 - 12:10 pm

Hi there,

I'm trying to use a function that will apply a rotation matrix at a given angle (which I'm calling alpha) to a set of second rank tensors. I have my set of tensors saved as a 3D wave where each wave layer represents the individual tensor, therefore my wave dimensions end up being (3,3,n) where n represents the number of individual tensors I'm trying to process. I haven't had any issues doing this exact operation on individual 2D waves (3x3) but the inclusion of the extra dimension doesn't seem to jive well since I get the following error:

error: MatrixOP can't overwrite a 3D or 4D wave that also appears on the RHS of the expression

Here's the code I'm trying to use:

Wave tensorWave //3D wave containing the tensor for each resonance. Each layer represents a resonance

Variable alpha //Tilt Angle

Duplicate/O tensorWave, tiltedTensor

Make/O/N=(3,3) rotMatAlignZ = {{cos(alpha*(Pi/180)),sin(alpha*(Pi/180)),0},{-sin(alpha*(Pi/180)),cos(alpha*(Pi/180)),0},{0,0,1}}

Make/O/N=(3,3) rotMatAlignY = {{cos(alpha*(Pi/180)),0,-sin(alpha*(Pi/180))},{0,1,0},{sin(alpha*(Pi/180)),0,cos(alpha*(Pi/180))}}

Make/O/N=(3,3) rotMatAlignX = {{1,0,0},{0,cos(alpha*(Pi/180)),sin(alpha*(Pi/180))},{0,-sin(alpha*(Pi/180)),cos(alpha*(Pi/180))}}

MatrixOP/O tiltedTensor = tiltedTensor x rotMatAlignY

End

Any suggestions on how to accomplish this?

Thanks!

Does this give the correct result? Commenting the Duplicate line and using

`MatrixOP/O tiltedTensor = tensorWave x rotMatAlignY`

instead of the final line of your function.

December 12, 2019 at 11:39 pm - Permalink

The error reported is to remind you that MatrixOP does not support expressions that involve the same 3D wave on both sides of the equation.

The suggestion of @srj51 is correct but it does not stress the point that the Duplicate command is not necessary because MatrixOP creates its own output waves.

Two minor points:

If you are going to be running this in a loop it might be useful to compute some of the trig functions once.

You can also perform rotations using quaternions (built in to MatrixOP in IP8). You can learn more about this by executing:

`DisplayHelpTopic "MatrixOp Quaternion Data Tokens"`

A.G.

December 13, 2019 at 10:48 am - Permalink