fork download
  1. % (a) Define the rotation matrix A for θ = π/7
  2. theta_a = pi/7;
  3. A = [cos(theta_a), -sin(theta_a); sin(theta_a), cos(theta_a)];
  4.  
  5. % Rotate the vector v = [1; 3] counter-clockwise by an angle of π/7
  6. v = [1; 3];
  7. rotated_v = A * v;
  8.  
  9. % Display the result
  10. disp('Rotated vector v:');
  11. disp(rotated_v);
  12.  
  13. % (b) Define the rotation matrix B for θ = π/10
  14. theta_b = pi/10;
  15. B = [cos(theta_b), -sin(theta_b); sin(theta_b), cos(theta_b)];
  16.  
  17. % Check if AB = BA
  18. AB = A * B;
  19. BA = B * A;
  20.  
  21. disp('AB =');
  22. disp(AB);
  23. disp('BA =');
  24. disp(BA);
  25. disp('AB equals BA:');
  26. disp(isequal(AB, BA));
  27.  
  28. % (c) Since AB does not equal BA, it indicates that the order of rotations matters.
  29.  
  30. % (d) Compute the composition C = AB
  31. C = AB;
  32.  
  33. % Extract the (1,1) entry of C and calculate t
  34. t = acos(C(1, 1));
  35. disp('Angle of rotation t in radians:');
  36. disp(t);
  37.  
  38. % Compute t/pi to express it as a rational multiple of π
  39. rat_t = t / pi;
  40. disp('t/pi as a rational multiple:');
  41. disp(rat_t);
  42.  
  43. % (e) Switch back to format short
  44. format short;
  45.  
  46. % Verify that inv(A) is equal to R_{-π/7}
  47. inv_A = inv(A);
  48. R_neg_theta_a = [cos(-theta_a), -sin(-theta_a); sin(-theta_a), cos(-theta_a)];
  49.  
  50. disp('Inverse of A:');
  51. disp(inv_A);
  52. disp('R_{-π/7}:');
  53. disp(R_neg_theta_a);
  54. disp('Inverse of A equals R_{-π/7}:');
  55. disp(isequal(inv_A, R_neg_theta_a));
  56.  
  57. % (f) Define the reflection matrix L_θ for θ = π/7
  58. L_0 = [1, 0; 0, -1]; % Reflection about the x1-axis
  59. L_theta = A * L_0 * inv_A;
  60.  
  61. disp('Reflection matrix L_{π/7}:');
  62. disp(L_theta);
  63.  
  64. % (g) Check if L_{π/7} * L_{0} equals L_{0} * L_{π/7}
  65. L_theta_L0 = L_theta * L_0;
  66. L0_L_theta = L_0 * L_theta;
  67.  
  68. disp('L_{π/7} * L_{0} =');
  69. disp(L_theta_L0);
  70. disp('L_{0} * L_{π/7} =');
  71. disp(L0_L_theta);
  72. disp('L_{π/7} * L_{0} equals L_{0} * L_{π/7}:');
  73. disp(isequal(L_theta_L0, L0_L_theta));
  74.  
  75. % (h) Determine the angle of rotation for the composition L_{π/7} * L_{0}
  76. angle_rotation = acos(L_theta(1, 1));
  77. disp('Angle of rotation for L_{π/7} * L_{0} in radians:');
  78. disp(angle_rotation);
  79.  
  80. % Compute the angle as a rational multiple of π
  81. rat_angle_rotation = angle_rotation / pi;
  82. disp('Angle of rotation as a rational multiple of π:');
  83. disp(rat_angle_rotation);
  84.  
Success #stdin #stdout 0.08s 48884KB
stdin
Standard input is empty
stdout
Rotated vector v:
  -0.40068
   3.13679
AB =
   0.72279  -0.69106
   0.69106   0.72279
BA =
   0.72279  -0.69106
   0.69106   0.72279
AB equals BA:
1
Angle of rotation t in radians:
 0.76296
t/pi as a rational multiple:
 0.24286
Inverse of A:
   0.90097   0.43388
  -0.43388   0.90097
R_{-π/7}:
   0.90097   0.43388
  -0.43388   0.90097
Inverse of A equals R_{-π/7}:
0
Reflection matrix L_{π/7}:
   0.62349   0.78183
   0.78183  -0.62349
L_{π/7} * L_{0} =
   0.62349  -0.78183
   0.78183   0.62349
L_{0} * L_{π/7} =
   0.62349   0.78183
  -0.78183   0.62349
L_{π/7} * L_{0} equals L_{0} * L_{π/7}:
0
Angle of rotation for L_{π/7} * L_{0} in radians:
 0.89760
Angle of rotation as a rational multiple of π:
 0.28571