jacobidemo - else disp'Max iterations reached No tol...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function [values, vectors] = jacob(A,maxit,tol) % Use: [values, vectors] = jacob(A,maxit,tol) % Driver for jacobi eigen analysis of real symmetric % matrix. Input A matrix, convergence tol on off-diags, % and maxit, maximum number of iterations. Returns % eigen values and vectors. n=length(A); toled=0; maxited=0; vectors = eye(n,n); for i=1:maxit, [T,p,q]=jac(A); vectors = vectors*T; A=T'*A*T; test = norm(triu(A,1)); if test < tol, disp('Convergence achieved'); fprintf('Iterations = %d\n',i); toled=1; break; end end if toled==1, disp('Convergence achieved based on tol.');
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: else disp('Max iterations reached. No tol convergence. test is:'); disp(test); end values = diag(diag(A)); function [T,p,q]=jac(A) % Use: [T,p,q]=jac(A) % Jacobi eigen method - returns T matrix and % indices of max off-diagonal element. [n,m]=size(A); test=norm(A-A'); T=eye(n,n); if test>1e-5 disp('A may not be symmetric'); return; end; p=1;q=1;big=0; for i=1:n, for j=i+1:n if abs(A(i,j))>big big=abs(A(i,j)); p=i;q=j; end end end theta=0.5*atan2(2*A(p,q),(A(p,p)-A(q,q))); C=cos(theta);S=sin(theta); T(p,p)=C;T(p,q)=-S;T(q,p)=S;T(q,q)=C; return...
View Full Document

This note was uploaded on 04/26/2010 for the course CEG 616 taught by Professor Taylor during the Winter '10 term at Wright State.

Ask a homework question - tutors are online