# HW3_soln - % A program to rotate a vector theta about % the...

This preview shows pages 1–2. Sign up to view the full content.

about % the z-axis % S. Swinnea % Inputs x = input( 'Enter x: '); y = input( 'Enter y: '); z = input( 'Enter z: '); theta = input( 'Enter rotation angle (degrees): '); r = [ x y z ]; T = [cosd(theta) -sind(theta) 0;sind(theta) cosd(theta) 0;0 0 1 ]; % Calculations % The next command is sneaky. It will % change "anything" into a column vector % I don't expect students to use it r = r(:); len_r = norm( r ); r_new = T*r; angle = acosd( r'*r_new/len_r^2 ); % Outputs fprintf('\n'); fprintf(' Coordinates\n x y z\n') fprintf('Original %0.1f %0.1f %0.1f\n' , r); fprintf('Rotated %0.1f %0.1f %0.1f\n' , r_new); fprintf('\nLength of Vector: %0.2f\n' , len_r); fprintf('Angle between Vectors: %0.2f\n' , angle); >> vector_rotate Enter x: .9 Enter y: .3 Enter z: 0 Enter rotation angle (degrees): 90 Coordinates x y z Original 0.9 0.3 0.0 Rotated -0.3 0.9 0.0 Length of Vector: 0.95 Angle between Vectors: 90.00

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 09/01/2011 for the course PHY 303 taught by Professor Erskine/tsoi during the Spring '08 term at University of Texas.

### Page1 / 4

HW3_soln - % A program to rotate a vector theta about % the...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online