lab4 mat 343

.pdf

School

Arizona State University *

*We aren’t endorsed by this school

Course

MISC

Subject

Mathematics

Date

Apr 3, 2024

Type

pdf

Pages

9

Uploaded by JusticeHedgehogMaster1052

MAT 343 LAB 4 - Amy Fishencord NOTE: For each of the following problems you must create a script M-file rseparately and invoke it here in your livescript file. Make sure the function file is in the same folder as this livescript. Delete these notes upon submission. Question 1 type lab4_exercise1.m %print the M-file for question 1 x = [0, 1, 1, 0, 0] y = [0, 0, 1, 1, 0] plot(x,y, 'o-') axis([-2,2,-2,2]) S = [0, 1, 1, 0, 0; 0, 0, 1, 1, 0] plot(S(1,:),S(2,:)) axis([-2,2,-2,2]) grid on % Amy Fish clf S=[0,1,1,0,0;0,0,1,1,0]; plot(S(1,:),S(2,:),'linewidth',2); hold on % Enter T = [1 0;2 1]; TS=T*S; plot(TS(1,:),TS(2,:),'-r','linewidth',2); title('Example of a vertical shear') legend('original square','sheared square','location','southeast') axis equal axis([-1 4 -1 4]) grid on hold off lab4_exercise1 % run the M-file for question 1 x = 1×5 0 1 1 0 0 y = 1×5 0 0 1 1 0 S = 2×5 0 1 1 0 0 0 0 1 1 0 1
Question 2 type lab4_exercise2.m %print the M-file for question 2 clear all; % clear all variables clf; % clear all settings for the plot S=[0,1,1,0,0;0,0,1,1,0]; plot(S(1,:),S(2,:),'linewidth',2); % plot the square hold on; theta =pi/6; % define the angle theta Q=[cos(theta),-sin(theta);sin(theta),cos(theta)]; % rotation matrix Q = [cos(theta),-sin(theta); sin(theta), cos(theta)]; QS = Q*S; plot(QS(1,:),QS(2,:),'-r','linewidth',2); % plot the rotated square title('Example of Rotation'); % add a legend('original square','rotated square') % add a legend axis equal; axis([-1,2,-1,2]); % set the window grid on; % add a grid hold off % Amy Fish clf S=[0,1,1,0,0;0,0,1,1,0]; plot(S(1,:),S(2,:),'linewidth',2); hold on theta = pi/6; Q=[cos(theta), -sin(theta);sin(theta), cos(theta)]; 2
T = [1 1;0 1]; QTS=Q*T*S; plot(QTS(1,:),QTS(2,:),'-r','linewidth',2); title('Example of shear and rotation') legend('original square','modified square','location','southeast') axis equal axis([-1 3 -1 3]) grid on hold off lab4_exercise2 % run the M-file for question 2 Is the result the same as Example? Does the order of the transformations matter? Answer: No it is not and yes the order of transformations matter. Question 3 For this exercise you are not supposed to include the picture, so you do not need to run the M-file type lab4_exercise3.m %print the M-file for question 3 clf S=[0,1,1,0,0;0,0,1,1,0]; 3
plot(S(1,:),S(2,:),'linewidth',2) hold on D = [2, 0; 0, 3]; % dilation matrix DS = D*S; plot(DS(1,:),DS(2,:),'-r','linewidth',2) title('Example of Dilation') legend('original square','dilated square','location','southeast') grid on axis equal, axis([-1,4,-1,4]) % adjust the axis and the window hold off %Amy Fish clear all; % clear all variable clf; % clear all setting for th plot S = [0,1,1,0,0;0,0,1,1,0]; theta = pi/9; % increment angle Q1 = [cos(theta),-sin(theta);sin(theta),cos(theta)]; % counter clockwise Ration matrix p = plot(S(1,:),S(2,:)); % plot the square axis([-2,2,-2,2]) % define axis size of graph axis square, grid on hold on % hold the current graph for i = 1:18 % for loop 18 time to rotate it full 360 degreen S = Q1*S; % rotate the squre set(p,'xdata',S(1,:),'ydata',S(2,:)); % erase original figure and plot pause(0.3) % pause for 0.3 sec end pause(1) % pause for 1 second when it is original position Q2 = [cos(-theta),-sin(-theta);sin(-theta),cos(-theta)]; % clockwise roation matrix for i = 1:18 % for loop 18 time to rotate it full 360 degreen S = Q2*S;% rotate the squre set(p,'xdata',S(1,:),'ydata',S(2,:));% erase original figure and plot pause(0.3)% pause for 0.3 sec end hold off; Question 4 For this exercise you are not supposed to include the picture, so you do not need to run the M-file type lab4_exercise4.m %print the M-file for question 4 clf S=[0,1,1,0,0;0,0,1,1,0]; plot(S(1,:),S(2,:),'linewidth',2) hold on T=[1,1;0,1]; % shear transformation matrix TS=T*S; plot(TS(1,:),TS(2,:),'-r','linewidth',2); title('Example of horizontal shear') legend('original square','sheared square','location','southeast') axis equal,axis([-1,3,-1,3]); grid on %adjust the axis and the window hold off %Amy FIsh clf S = [0, 1, 1, 0, 0;0, 0, 1, 1, 0]; D1 = 10/9*eye(2); p = plot(S(1,:),S(2,:)); axis([-8,8,-8,8]); axis square, grid on hold on % Create rotation matrix % In counterclockwise direction R = @(theta)[cosd(theta) -sind(theta); sind(theta) cosd(theta)]; % defining theta for rotation angle 4
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help