% Diary file from Matlab for hw1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Problem 2: A=[10 -3; 4 2], B=[1 0; -1 2], v=[1; 2], w=[1; 1] A = 10 -3 4 2 B = 1 0 -1 2 v = 1 2 w = 1 1 % 2(a): v'*w ans = 3 % 2(b): v*w' ans = 1 1 2 2 % 2(e): A*B ans = 13 -6 2 4 % 2(f) B*A ans = 10 -3 -2 7 % 2(h) y=B\w y = 1 1 % 2(i) x=A\v x = 0.2500 0.5000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Problem 3: x=[0:.01:2*pi]'; for k=1:5, y=sin(k*x); plot(x,y), hold on; end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Problem 6: figure(2) % Put plot on a new graph. subplot(2,2,1) % Use subplot to put 4 graphs on same page. x=[-3:.01:3]'; y = abs(x-1); plot(x,y); title('y = abs(x-1)') subplot(2,2,2) x=[-4:.01:4]'; y=sqrt(abs(x)); plot(x,y); title('y = sqrt(abs(x))') subplot(2,2,3) x=[-4:.01:4]'; y=exp(-x.^2); plot(x,y); title('y = exp(-x^2)') subplot(2,2,4) x=[-2:.01:2]'; y=1./(10*x.^2+1); plot(x,y); title('y = 1/(10 x^2 + 1)') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Problem 11: figure(3) % Put plot on a new graph. % 11(a): % Create matrix whose columns contain coords of each vertex of the square. U = [1 2 2 1; -.5 -.5 .5 .5]; % Plot a red square. fill(U(1,:),U(2,:),'r') % Adjust axes. axis('equal'); axis([-4 4 -4 4]); hold on % Create rotation matrix. theta = pi/4; R = [cos(theta), -sin(theta); sin(theta), cos(theta)]; % Rotate each of the vertices and color the rotated square blue. U = R*U; fill(U(1,:),U(2,:),'b') % Continue rotating, coloring rotated squares different colors. U = R*U; fill(U(1,:),U(2,:),'g') U = R*U; fill(U(1,:),U(2,:),'y') U = R*U; fill(U(1,:),U(2,:),'m') U = R*U; fill(U(1,:),U(2,:),'c') U = R*U; fill(U(1,:),U(2,:),'r') U = R*U; fill(U(1,:),U(2,:),'b') U = R*U; fill(U(1,:),U(2,:),'g') % This square lands on top of original. % 11(b): figure(4) % Put next plot on a new graph. U=[5 6 4; 0 2 1]; fill(U(1,:),U(2,:),'r') % Plot initial red triangle. hold on % Put next plot on same graph. theta = pi/2; R = [cos(theta), -sin(theta); sin(theta), cos(theta)]; U = R*U; % Rotate pi/2 radians. fill(U(1,:),U(2,:),'b') % Plot rotated triangle in blue. U = R*U; % Rotate another pi/2 radians for a total of pi. fill(U(1,:),U(2,:),'g') % Plot rotated triangle in green. U = R*U; % Rotate another pi/2 radians for a total of 3*pi/2. fill(U(1,:),U(2,:),'y') % Plot rotated triangle in yellow. axis('equal') % 11(c): % Verify that R(theta) and R(-theta) are inverses of each other % for theta=pi/3 and theta=pi/4. theta=pi/3; Rtheta = [cos(theta), -sin(theta); sin(theta), cos(theta)]; Rmtheta = [cos(-theta), -sin(-theta); sin(-theta), cos(-theta)]; Rtheta*Rmtheta ans = 1 0 0 1 % This is the identity, so Rtheta and Rmtheta are inverses of each other. theta = pi/4; Rtheta = [cos(theta), -sin(theta); sin(theta), cos(theta)]; Rmtheta = [cos(-theta), -sin(-theta); sin(-theta), cos(-theta)]; Rtheta*Rmtheta ans = 1 0 0 1 % This is the identity, so Rtheta and Rmtheta are inverses of each other. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% exit