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

📄 oneptrlx.mht

📁 it is a very essential matlab code.
💻 MHT
字号:
From: <Saved by Windows Internet Explorer 7>
Subject: 
Date: Tue, 12 May 2009 09:44:32 -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/oneptrlx.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>% Demonstration of Gauss-Seidel (One Point Iteration) Root =
Finding
%
% The function is defined in the file 'fcn.m'. The contents of this file =
are:
%
%      function y =3D fcn(x)
%      y =3D -1200/(x^3 - 5*x^2 - 124*x + 380);

fprintf('\nDemonstration of One Point Iteration with relaxation\n');

       x =3D input ('Enter initial guess of root:        ');
       w =3D input ('Enter relaxation factor:            ');
maxerror =3D input ('Enter maximum error (percent):      ');
   maxit =3D input ('Enter maximum number of iterations: ');

xinit =3D x;
for wloop =3D 1:14    % test out 0.1 &lt;=3D w &lt;=3D 1.4
  x =3D xinit;
  w =3D wloop * 0.1;
  count =3D 0;   % iteration counter
  error =3D 1;   % starting error (100 percent)

%  fprintf('\n Iteration      x    g(x)=3Dxnew  error(percent)\n\n');

  while (error &gt; maxerror) &amp; (count &lt; maxit)   % '&amp;' is =
logical AND
    count =3D count + 1;
    temp =3D fcn(x);
    xnew =3D x + w * (temp - x);
    error =3D abs((xnew - x)/xnew) * 100;
%   fprintf('%7g %10.4f %10.4f %10.4f\n',count,x,xnew,error);
    x =3D xnew;
  end
  wvect(wloop) =3D w;
  countvect(wloop) =3D count;
  fprintf('w =3D %g   # iter =3D %g\n',w,count)
end

quickplt(wvect,countvect,'relaxation factor (w)','# of iterations',...
         'optimal relaxation for one-point iteration')
</PRE></BODY></HTML>

⌨️ 快捷键说明

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