📄 gssor.mht
字号:
From: <Saved by Windows Internet Explorer 7>
Subject:
Date: Tue, 12 May 2009 09:48:02 -0700
MIME-Version: 1.0
Content-Type: text/html;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://www.mece.ualberta.ca/Courses/mec390/390code/gssor.m
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 6.00.6000.16825" name=3DGENERATOR></HEAD>
<BODY><PRE>% Illustration of Gauss Seidel iteration with relaxation
%
% The goal is to determine a set of values of x1...x4 that=20
% satisfy the following equations...
% f1(x1,x2,x3,x4) =3D -2*x1 + x2 + 1.5 =3D 0
% f2(x1,x2,x3,x4) =3D x1 - 2*x2 + x3 - 0.5 =3D 0
% f3(x1,x2,x3,x4) =3D x2 - 2*x3 + x4 - 0.5 =3D 0
% f4(x1,x2,x3,x4) =3D x3 - 2*x4 + 0.5 =3D 0
%
% We will take an x1 out of f1 and an x2 out of f2 and so on.
% The g functions are defined in files 'lin_g1.m' through 'lin_g4.m'
fprintf('\nSolution of System of Equations using GS iteration with =
Relaxation\n');
x1 =3D input('Enter x1 estimate : ');
x2 =3D input('Enter x2 extimate : ');
x3 =3D input('Enter x3 estimate : ');
x4 =3D input('Enter x4 extimate : ');
w =3D input('Enter relaxation factor : ');
maxerror =3D input('Enter max approx error : ');
maxit =3D input('Enter max # of iterations: ');
count =3D 0;
error =3D 100;
fprintf('\niteration x1 x2 x3 x4\n');
while (error > maxerror) & (count < maxit)
count =3D count + 1;
temp =3D lin_g1(x1,x2,x3,x4);
x1new =3D x1 + w*(temp-x1);
temp =3D lin_g2(x1new,x2,x3,x4);
x2new =3D x2 + w*(temp-x2);
temp =3D lin_g3(x1new,x2new,x3,x4);
x3new =3D x3 + w*(temp-x3);
temp =3D lin_g4(x1new,x2new,x3new,x4);
x4new =3D x4 + w*(temp-x4);
error1 =3D abs(x1new - x1);
error2 =3D abs(x2new - x2);
error3 =3D abs(x3new - x3);
error4 =3D abs(x4new - x4);
error =3D max([error1,error2,error3,error4]);
=20
fprintf('%6i %10.6f %10.6f %10.6f %10.6f\n',...
count,x1new,x2new,x3new,x4new);
x1 =3D x1new; % assign new values
x2 =3D x2new;
x3 =3D x3new;
x4 =3D x4new;
end
</PRE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -