# Jacobi - if(A(i,j< sum error'convergence criteria is not...

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

Jacobi file:///C:/Documents%20and%20Settings/DCM/My%20Documents/M. .. 1 of 2 10/28/2009 1:02 PM function xnew=Jacobi(A,b,maxerr,maxiter,guess) if (nargin <2) error( 'at least two arguments required' ) return end if (nargin < 3) maxerr=0.00001; end if (nargin < 4) maxiter=100; end [n,m] = size(A); if (n~=m) error( 'A is not a square matrix' ) return ; end [k,k1]=size(b) if (k~=n) error( 'the dimensions of A and b do not match' ) return ; end if (nargin < 5) for i=1:n guess(i)=0.0 end ; end for i=1:n sum=0 for j=1:n if (j~=i) sum = sum + A(i,j) end end
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (A(i,j) < sum ) error( 'convergence criteria is not satisfied' ); return end end xnew=zeros(n); D=zeros(n,n) for i=1:n D(i,i)=A(i,i) end R=zeros(n,n) R=A-D D1 = inv(D) C=D1*b E=D1*R xoldt = guess' for i=1:maxiter F=E*xoldt xnewt = C-F xnew=xnewt' xold=xoldt' for k=1:n relerr=zeros(n); relerr(k) = abs((xnew(1,k)-xold(1,k))/xnew(1,k)); end if (max(relerr) < maxerr) return ; end xoldt = xnewt iteration=i end Error using ==> Jacobi at 3...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online