disp('%') disp('% Homework check for section 6.1: Eigenvalues') disp('%') disp('% This sections uses many technical terms from chapters 3 thru 5.') disp('% The students are not responsible for this material at this time.') disp('%') disp('% Definition: A scalar s is an eigenvalue of the matrix A correspon-') disp('% ding to the nonzero eigenvector x if Ax=sx.') disp('% ') disp('% Algorithm: Calculate the characteristic polynomial det(sI-A)') disp('% and its roots, which are the eigenvalues. For each eigenvalue s') disp('% solve the systems of equations Ax=sx for the eigenvectora(s) x.') disp('%') disp('% Other noteworthy theorems of thsi section:') disp('% The product of the eigenvalues (with multiplicities) equals det(A).') disp('% If U is an invertibe matrix with inverse Uinv, then A and Uinv*A*U') disp('% have the same eigenvalues.') pause disp('%') disp('The characteristic polynomial is a quadratic') disp('% Problem 6:') A=[1 2 4;0 3 5;0 0 2] disp('Use the command "poly" to calculate the characteristic') disp('Its coefficients are') p=poly(A) pause disp('Use the command "roots" to calculate its roots, that is') disp('the eigenvalues of the matrix A') ss=roots(p) pause disp('Since it is so easy, always take a look at the graph of the') disp('characteristic polynomial -- activitate the figure window!') xx=[-5:.1:5]; yy=polyval(p,xx); plot([-5,5],[0,0],'g-',[0,0],[-5,5],'c-'); hold on plot(xx,yy,'m',ss,[0,0,0],'yo'); axis([-5,5,-5,5]) pause disp('To solve for the corresponding eigenvectors, rowreduce the') disp('matrices (sI-A), for each eigenvalue s found above.') s1=ss(1) A1=s1*eye(3)-A R1=rref(A1) pause disp('One nontrivial solution for this system is:') pause v1=[1;1;0] disp('We check this by mutliplying our solution by the reduced matrix R1') pause check=R1*v1 disp('This is zero within working precision, i.e. the solution is correct') pause disp('%') disp('As an alternative check, calculate A*v1 and compare to s1*v1') pause v1 Av1=A*v1 s1v1=s1*v1 pause disp('We repeat the above steps for the second eigenvalue:') pause s2=ss(2) A2=s2*eye(3)-A R2=rref(A2) pause disp('One nontrivial solution for this system is:') pause v2=[6;5;-1] disp('We check this by mutliplying our solution by the reduced matrix R2') pause check=R2*v2 disp('This is zero within working precision, i.e. the solution is correct') pause disp('%') disp('As an alternative check, calculate A*v2 and compare to s2*v2') pause v2 Av2=A*v2 s2v2=s2*v2 pause disp('We repeat the above steps for the third eigenvalue:') pause s3=ss(3) A3=s3*eye(3)-A R3=rref(A3) pause disp('One nontrivial solution for this system is:') pause v3=[1;0;0] disp('We check this by mutliplying our solution by the reduced matrix R3') pause check=R3*v3 disp('This is zero within working precision, i.e. the solution is correct') pause disp('%') disp('As an alternative check, calculate A*v3 and compare to s3*v3') pause v3 Av3=A*v3 s3v3=s2*v3 pause disp('Finally we check our work against the built-in "eig" command:') [EVectors,EVals]=eig(A) disp('and compare this to our solution: D=diag([s1,s2,s3]) and V=transpose of [v1,v2,v3]') pause V=[v1,v2,v3] D=diag([s1,s2,s3]) v2unit=v2/sqrt(v2'*v2) disp('We see that up to the ordering and normalization, the solutions agree') disp('where v2unit=v2/sqrt(v2''*v2) is the unit vector in the direction of v2.') pause disp('%') disp('%') disp('%') hw61a