Gauss_Seidel_Method

# Gauss_Seidel_Method -...

This preview shows pages 1–2. Sign up to view the full content.

function Gauss_Seidel_Method(A,b,es,lam) %Problem 12.1 %Uses the gauss seidel method to solve the passed system %until the percent relative error falls below es. %A=coefficient matrix, 3x3 %b=column vector of knowns %es=tolerance specified %lam=weighting factor x2=0; x3=0; x1_old=0; x2_old=0; x3_old=0; i=0; [m,n]=size(A); error('---->>Coefficient matrix must be a 3x3'); elseif nargin<3, error('At least 3 inputs are needed, coefficient matrix & column vector of knowns & error'); elseif nargin==3||isempty(lam),lam=0; end while(1) x1=(b(1,1)-A(1,2)*x2-A(1,3)*x3)/A(1,1);

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: x2=(b(2,1)-A(2,1)*x1-A(2,3)*x3)/A(2,2); x3=(b(3,1)-A(3,1)*x1-A(3,2)*x2)/A(3,3); if lam>1 && lam<2 %really want to use a for loop, is there any way? %method for overrelaxation, which is designed to accelerate the %convergent system. x1=(1-lam)*x1_old+lam*(; x2=(1-lam)*x2_old; x3=(1-lam)*x3_old; end ea=abs((x1-x1_old)/x1)*100; x1_old=x1; i=i+1; if ea<=es fprintf('\nAfter %d iterations, x1=%7.4f, x2=%7.4f, x3=%7.4f, maximum error=%4.3f percent\n\n',i,x1,x2,x3,ea); break end end...
View Full Document

## This note was uploaded on 09/27/2011 for the course EGM 3344 taught by Professor Raphaelhaftka during the Spring '09 term at University of Florida.

### Page1 / 2

Gauss_Seidel_Method -...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online