find_largest_eig - elseif tol<0 error'Please input a...

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

View Full Document Right Arrow Icon
function [eigenvalue, eigenvector] = find_largest_eig (A,tol,max_iter) [rA,cA]=size(A); if rA~=cA error('Matrix A must be square!') elseif det(A)<sqrt(eps) warning('EX:Warn1','The matrix A is nearly singular, therefore the method may fail') end if max_iter<=0 error('Please input max_iter > 0')
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: elseif tol<0 error('Please input a tol > 0') end n=0; x0=ones(rA,1); x1=x0; while min(max(abs(x0-x1)), max(abs(x0+x1))) < tol n=n+1; x1=A*x0; x1=x1/norm(x1); x0=x1; if n>max_iter break end end eigenvector=x1; eigenvalue=x1'*A*x1;...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online