% % Data points for the final exam MAT 342, Fall 1996 % p=[1 -2; 1 0; 5 0; 2 4; 3 4; 0 7; -3 4; -2 4; -4 1; -4 0; -1 0; -1 -2; 1 -2]' q=[24 5;20 5;20 9;12 6;12 7; 6 4; 12 1; 12 2; 18 0; 20 0; 20 3; 24 3;24 5]' % % ffill(p,'g') hold on ffill(q,[.5 .3 0]) grid % % % % disp('strike any key to continue') pause % % % disp('Hint: Given a 2x2-matrix A and a 2x2 vector v, draw the') disp(' image of the polygon p under the map x --> Ax+v ') disp(' using the following commands -- just an example.') % A=[2 0;0 .6] v=[0;-10] % disp('You need to make v into a matrix of the same size as p') disp('strike any key to continue') pause disp('Overlay the new plot -- look at the graphics window!') % % disp(' ') echo on vv=diag(v')*ones(size(p)) ffill(A*p+vv,'b') echo off disp(' ') disp(' ') % disp('Trial and error solutions will not earn credit. You need') disp('to demonstrate how to use linear algebra effectively to') disp('find the matrix A and the vector v such that x --> Ax+v') disp('maps the green tree into the given brown one.') % disp(' ') disp('Strike any key to continue for the solution.') pause % disp('Write out the matrix equation Pnew = A * Qnew + v in coordinates') disp(' ') disp(' xnew=a11*xold+a12*yold+v1 one equation for each point') disp(' ynew=a21*xold+a22*yold+v2 one equation for each point') disp(' ') disp('For clarity we only use the first three points, and write the system') disp('of equations in matrix from: AA * XX = BB, where XX is the vector') disp('of unknowns XX=[a11 a12 v1 a21 a22 v2]'', BB is a vector with coords') disp('of the new points BB=[xnew1 xnew2 xnew3 ynew1 ynew2 ynew3]'', and AA') disp('a 6x6 matrix containing the coordinates of the old points:') disp(' ') disp('Strike any key to continue') pause % BB=[q(1,1:3) q(2,1:3)]' AA=[p(1,1:3)' p(2,1:3)' ones([3,1]) zeros([3,3]); ... zeros([3,3]) p(1,1:3)' p(2,1:3)' ones([3,1])] % disp('You may decide to type in the matrix by hand; it is not too large.') disp(' ') disp('Next solve the system of equations -- create A and v, and check:') disp('Strike any key to continue') pause % XX=AA\BB A=[XX(1) XX(2); XX(4) XX(5)] v=[XX(3);XX(6)] pplot(A*p+diag(v')*ones(size(p)),'m') % disp('Check the graph for a visual check.') disp('Strike any key when ready to continue with an algebraic check:') % disp('old points') p disp('given new points') q disp('calculated new points') qq=A*p+diag(v')*ones(size(p)) disp('take the difference of the two matrices and display min and max entry') [min(min(q-qq)),max(max(q-qq))] disp(' ') disp('There is a much less naive solution -- but it takes some xperience') disp('to immediately come up with the solution. The key is to first eliminate') disp('the translation -- the trick is to only consider differences of points!') disp('E.g. A*p1+v=q1 and A*p2+v=q2 leads to A(p2-p1)=(q2-q1) -- the v''s are gone!') disp('Note, since A*pdiff=qdiff, we need A=qdiff/pdiff -- division on the right!') disp(' ') disp('Strike any key when ready to continue') disp(' ') echo on pdiff=p(:,2:12)-p(:,1:11) qdiff=q(:,2:12)-q(:,1:11) AA=qdiff(:,1:2)/pdiff(:,1:2) AA=qdiff/pdiff vv=q-AA*p v=v(:,1) disp('Merry Xmas and Happy Holidays')