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

Report
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
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
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
theta = 180/10; for i=1:10 S = D1*S; % multiplying with R(theta) for rotating points S = R(theta)*S; set(p,'xdata',S(1,:),'ydata',S(2,:)); pause (0.1); end D2 = 9/10*eye(2); % defining theta in negative to rotate in counterclockwise direction theta = -180/10; for i=1:10 S = D2*S; % multiplying with R(theta) for rotating points S = R(theta)*S; set(p,'xdata',S(1,:),'ydata',S(2,:)); pause (0.1); end hold off Question 5 type lab4_exercise5.m %print the M-file for question 5 clf S=[0,1,1,0,0;0,0,1,1,0]; plot(S(1,:),S(2,:),'linewidth',2) hold on theta=pi/6; % define the angle Q=[cos(theta), -sin(theta); sin(theta), cos(theta)]; T=[1,1;0,1]; % shear transformation matrix TQS=T*Q*S; plot(TQS(1,:),TQS(2,:),'-r','linewidth',2); title('Example of rotation and shear') legend('original square','modified square','location','southeast') axis equal , axis ([ -1 ,3 , -1 ,3]); grid on % adjust the axis and the window hold off lab4_exercise5 % run the M-file for question 5 5
Question 6 For this exercise you are not supposed to include the picture, so you do not need to run the M-file type lab4_exercise6.m %print the M-file for question 6 p = plot(S(1,:),S(2,:)) set(p,’xdata’,S(1,:),’ydata’,S(2,:)); clf S=[0,1,1,0,0;0,0,1,1,0]; D1 = 9/8* eye (2); p = plot(S(1,:),S(2,:)); axis([-1,4,-1,4]) % % % % % % clear all settings for the plot axis square , hold on grid on dilation plot the set size make the hold the matrix square of the graph display square current graph % dilate the square % erase original figure and plot % the transformed figure for end D2 = for i = S = set(p,'xdata',S(1,:),'ydata',S(2,:)); 1:10 D1*S; pause(0.1) % adjust this pause rate to suit your computer. % contraction matrix 6
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
% contract the square % erase original figure and plot % the transformed figure 8/9* eye (2); i = 1:10 S = D2*S; set(p,'xdata',S(1,:),'ydata',S(2,:)); pause(0.1) % adjust this pause rate to suit your computer. end hold off Question 7 For this exercise you are not supposed to include the picture, so you do not need to run the M-file type lab4_exercise7.m %print the M-file for question 7 clf S=[0,1,1,0,0;0,0,1,1,0;1,1,1,1,1]; % square in homogeneous coordinates M=[1,0,4;0,1,-2;0,0,1]; % translati MS=M*S; % apply the translation to the square plot(S(1,:),S(2,:),'k','linewidth',2); % plot the original s plot(MS(1,:),MS(2,:),'r','linewidth',2); % plot the translated square in red legend('original square','tra axis equal, axis([-1,6,-3,4]), grid on % adjust the axis hold off S=[0,1,1,0,0;0,0,1,1,0;1,1,1,1,1]; M=[1,0,4;0,1,1;0,0,1]; % reflection matrix MS=M*S; % refleted matrix plot(MS(1,:),MS(2,:),'k','linewidth',2); % plot the translated square hold on R=[0,1,0;0,1,-2;0,0,1] RMS=R*MS plot(RMS(1,:),RMS(2,:),'r','linewidth',2); % plot the reflected square plot([-3,6],[-3,6]) % plot line y=x legend('translated Square','Reflected Square','the line y=x','Location','southeast'); axis equal axis([-3,6,-3,6]), grid on hold off Question 8 type lab4_exercise8.m %print the M-file for question 8 clf S=[0,1,1,0,0;0,0,1,1,0;1,1,1,1,1]; % square in homogeneous coordinates M1 = [1 ,0 ,0.4;0 ,1 ,0;0 ,0 ,1]; % first translation matrix M2 = [1 ,0 ,0;0 ,1 ,0.4;0 ,0 ,1]; % the second translation matrix p = plot(S(1,:),S(2,:)); % plot the original square axis square, axis([-1,10,-1,10]), grid on for i = 1:20 S = M1*S; % compute the translated square set(p,'xdata',S(1,:),'ydata',S(2,:)); % pause (0.1) end for i = 1:20 S=M2*S; % compute the translated square set(p,'xdata',S(1,:),'ydata',S(2,:)); % pause (0.1) end clf S=[0,1,1,0,0;0,0,1,1,0;1,1,1,1,1]; % define the square in homogenous co-ordinates 7
M1=[1,0,0.4;0,1,0;0,0,1]; % define first translation matrix M2=[1,0,0;0,1,0.4;0,0,1]; % define second translation matrix M3=[1,0,-0.4;0,1,-0.4;0,0,1]; % define thrid translation matrix p=plot(S(1,:),S(2,:)); % plot the original square axis([-1,14,-1,14]),grid on axis square for i=1:20 S=M1*S; %translate the square horizontally set(p,'xdata',S(1,:),'ydata',S(2,:)); %plot the translated square pause(0.1); end for i=1:20 S=M2*S; %translate the square vertically set(p,'xdata',S(1,:),'ydata',S(2,:)); %plot the translated square pause(0.1); end for i=1:20 S=M3*S; %translate reverse set(p,'xdata',S(1,:),'ydata',S(2,:)); %plot the translated square pause(0.1); end Question 9 type lab4_exercise8.m clf S=[0,1,1,0,0;0,0,1,1,0;1,1,1,1,1]; % square in homogeneous coordinates M1 = [1 ,0 ,0.4;0 ,1 ,0;0 ,0 ,1]; % first translation matrix M2 = [1 ,0 ,0;0 ,1 ,0.4;0 ,0 ,1]; % the second translation matrix p = plot(S(1,:),S(2,:)); % plot the original square axis square, axis([-1,10,-1,10]), grid on for i = 1:20 S = M1*S; % compute the translated square set(p,'xdata',S(1,:),'ydata',S(2,:)); % pause (0.1) end for i = 1:20 S=M2*S; % compute the translated square set(p,'xdata',S(1,:),'ydata',S(2,:)); % pause (0.1) end clf S=[0,1,1,0,0;0,0,1,1,0;1,1,1,1,1]; % define the square in homogenous co-ordinates M1=[1,0,0.4;0,1,0;0,0,1]; % define first translation matrix 8
M2=[1,0,0;0,1,0.4;0,0,1]; % define second translation matrix M3=[1,0,-0.4;0,1,-0.4;0,0,1]; % define thrid translation matrix p=plot(S(1,:),S(2,:)); % plot the original square axis([-1,14,-1,14]),grid on axis square for i=1:20 S=M1*S; %translate the square horizontally set(p,'xdata',S(1,:),'ydata',S(2,:)); %plot the translated square pause(0.1); end for i=1:20 S=M2*S; %translate the square vertically set(p,'xdata',S(1,:),'ydata',S(2,:)); %plot the translated square pause(0.1); end for i=1:20 S=M3*S; %translate reverse set(p,'xdata',S(1,:),'ydata',S(2,:)); %plot the translated square pause(0.1); end 9
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