Physics 350:
Computational Methods
for the Physical Sciences

Spring Semester 2009

Lab 7: Rotational Transforms Sample Solutions 

As usual, reset things.  But in this case we also want to load a couple of prebuilt Maple routines for linear algebra. 

> restart: with(linalg):

1. Identify the matrix for a rotation through angle φ about the positive z axis.  Well, this is just the standard rotation matrix we have had in many places (example on p. 416) where we make sure to leave the z-axis unchanged: 

> R := matrix([[cos(phi),-sin(phi),0],[sin(phi),cos(phi),0],[0,0,1]]);
`:=`(R, Matrix(%id = 9617188))

2. Identify the 3×3 matrix for the transformation which brings the point (1,1,1) to the point (0,0,sqrt(3)) via a counterclockwise rotation about the line from the point (1,–1,0) to the origin (looking toward the origin). The rotation is through angle α, where cos (α) = 1/sqrt(3) .  This is the same as rotating a line about the z-axis 45? counter-clockwise followed by some rotation about the x-axis.  So first I write my matrix for rotating about the z-axis 45?: 

> M1 := matrix([[cos(Pi/4),-sin(Pi/4),0],[sin(Pi/4),cos(Pi/4),0],[0,0,1]]);
`:=`(M1, Matrix(%id = 11742516))
> test := vector ([1,1,1]);
`:=`(test, Vector[row](%id = 11937628))
> test_rot := evalm(M1 &* test);
`:=`(test_rot, Vector[row](%id = 12146748))

Now I have to figure out how much I have to rotate by to get this rotated vector onto the z-axis, I can use a dot product (since A•B = ABcos(theta) ==> theta = arccos(A•B/AB) ) to figure out the angle between this and the "final" vector we want: 

> final := vector ([0,0,sqrt(3)]);
`:=`(final, Vector[row](%id = 12357096))
> theta := arccos(dotprod(test_rot, final) / dotprod(final,final)); cos_angle := cos(theta); sin_angle := sin(theta);

 

 

arccos(`+`(`*`(`/`(1, 3), `*`(`^`(3, `/`(1, 2))))))

`+`(`*`(`/`(1, 3), `*`(`^`(3, `/`(1, 2)))))

`+`(`*`(`/`(1, 3), `*`(`^`(6, `/`(1, 2)))))

So the cosine of the angle of rotation is 1/sqrt(3), therefore the rotation matrix for this second rotation about the x-axis is: 

> M2 := matrix([[1,0,0],[0,cos_angle,-sin_angle],[0,sin_angle,cos_angle]]);
`:=`(M2, Matrix(%id = 11950096))

So the matrix representing the rotation is the matrix product of these two rotations: 

> M := evalm(M2 &* M1);
`:=`(M, Matrix(%id = 10132348))
> test_rot2 := simplify(evalm(M &* test));
`:=`(test_rot2, Vector[row](%id = 3089204))

Finally I am asked to have Maple compute the inverse of this matrix: 

> Minv := evalm(1/M);
`:=`(Minv, Matrix(%id = 13470208))

3. Our next task is to find the matrix that rotates counterclockwise by an angle φ about the line segement from point (1,1,1) to the origin.  We are given the hint that we should be thinking of Minv*R*M.  In in fact, this makes sense, because what we are doing is rotating the axis of rotation onto the z-axis, then applying a rotation about the z-axis (which corresponds to our original (1,1,1) axis), then inverting the rotation.  Therefore a quick bit of Maple should find this rotation matrix: 

> S := simplify(evalm( Minv &* R &* M));
`:=`(S, Matrix(%id = 13342824))
`:=`(S, Matrix(%id = 13342824))
`:=`(S, Matrix(%id = 13342824))
`:=`(S, Matrix(%id = 13342824))

a. And now we confirm that a rotation of 120? just swaps axes.  To do this, I substitute phi = 120? = 2*Pi/3 (radians) into the matrix S and then test the resulting matrix: 

> S120 := simplify(subs(phi=2*Pi/3,matrix(S)));
`:=`(S120, Matrix(%id = 12824648))
> ihat := vector ([1,0,0]); jhat := vector([0,1,0]); khat := vector([0,0,1]);

 

 

`:=`(ihat, Vector[row](%id = 13107048))

`:=`(jhat, Vector[row](%id = 556880))

array( 1 .. 3, [( 1 ) = 0, ( 2 ) = 0, ( 3 ) = 1 ] )
> inew := evalm( S120 &* ihat); jnew := evalm( S120 &* jhat); knew := evalm( S120 &* khat);

 

 

`:=`(inew, Vector[row](%id = 3339916))

`:=`(jnew, Vector[row](%id = 11993108))

array( 1 .. 3, [( 1 ) = 1, ( 2 ) = 0, ( 3 ) = 0 ] )

b. Now see where (1,2,4) goes after a rotation of 60? about this axis. 

> S60 := simplify(subs(phi=Pi/3,matrix(S)));
`:=`(S60, Matrix(%id = 10162596))
> vec124 := vector([1,2,4]); vec124_new := evalm(S60 &* vec124);

 

`:=`(vec124, Vector[row](%id = 9642116))

array( 1 .. 3, [( 1 ) = `/`(8, 3), ( 2 ) = `/`(2, 3), ( 3 ) = `/`(11, 3) ] )

c. See where point (1,1,0) goes after a 90? rotation about this axis. 

> S90 := simplify(subs(phi=Pi/2,matrix(S)));
`:=`(S90, Matrix(%id = 3841460))
> vec110 := vector([1,1,0]); vec110_new := evalm(S90 &* vec110);

 

`:=`(vec110, Vector[row](%id = 13821008))

array( 1 .. 3, [( 1 ) = `+`(`/`(2, 3), `-`(`*`(`/`(1, 3), `*`(`^`(3, `/`(1, 2)))))), ( 2 ) = `+`(`*`(`/`(1, 3), `*`(`^`(3, `/`(1, 2)))), `/`(2, 3)), ( 3 ) = `/`(2, 3) ] )