⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gssornl.mht

📁 it is a very essential matlab code.
💻 MHT
字号:
From: <Saved by Windows Internet Explorer 7>
Subject: 
Date: Tue, 12 May 2009 09:48:33 -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/gssornl.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
%
% NON-LINEAR SYSTEM
%
% The goal is to determine a value of x1 and x2 that simultaneously
% satisfy the following equations...
%
%   f1(x1,x2) =3D x1^2 + x2^2 + exp(x1) - 7.7183*x1 =3D 0
%   f2(x1,x2) =3D x2 + exp(x2) + x1^3 - 10.389      =3D 0
%
% we will take an x1 out of f1(x1,x2) and an x2 out of f2(x1,x2)
% thus we will have
%
%   x1 =3D g1(x1,x2) =3D (x1^2 + x2^2 + exp(x1))/7.7183 and
%   x2 =3D g2(x1,x2) =3D 10.389 - exp(x2) - x1^3
%
% The g-functions are defined in files 'g1.m' and 'g2.m'
%

clear;

fprintf('\nSolution of Non-Linear Equations using Gauss-Seidel =
iteration\n');

      x1 =3D input('Enter x1 estimate         : ');
      x2 =3D input('Enter x2 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 1;

fprintf('\niteration      x1           x2      max error\n');

while (error &gt; maxerror) &amp; (count &lt; maxit)
    count =3D count + 1;

    temp =3D g1(x1,x2);
    x1new =3D x1 + w * (temp - x1);

    temp =3D g2(x1new,x2);
    x2new =3D x2 + w * (temp - x2);

    error1 =3D abs(x1new - x1);
    error2 =3D abs(x2new - x2);
    error =3D max([error1,error2]);
 =20
    fprintf('%6g    %10g %10g %10g\n',count,x1new,x2new,error);

    x1 =3D x1new;                           % assign new values
    x2 =3D x2new;
end

</PRE></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -