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

📄 onepoint.mht

📁 it is a very essential matlab code.
💻 MHT
字号:
From: <Saved by Windows Internet Explorer 7>
Subject: 
Date: Tue, 12 May 2009 09:44:15 -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/onepoint.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 One Point Iteration
clear; figure(1);clf;figure(2);clf;figure(1)

f =3D 'exp(-x)-x';       %define the function f(x)=3D0
g =3D 'exp(-x)';         %and a    x =3D g(x)   form

disp(['f(x) is ' f]);=20
disp(['g(x) is ' g]);

% plot the function
xmax=3D3;
grange =3D [-xmax xmax];
figure(1); ezplot(f,grange); hold on; line (grange, [0 0]); pause

% have a look at the g(x) function
figure(2); ezplot(g,[-1 xmax]);=20
hold on
plot([-1 xmax], [-1 xmax],'g')  % line defines x =3D x


x =3D input ('Enter initial guess of root:        ');
if length(x)=3D=3D0;x=3D0;end
maxerror =3D 0.1; % maximum error
   maxit =3D 30;  % maximum number of iterations
   count =3D 0;   % iteration counter
   error =3D 1;   % starting error (100 percent)

fprintf('\n Iteration      x       g(x)     error(%%)    f(x)\n\n');


% this is where all the work gets done.....
while (error &gt; maxerror) &amp; (count &lt; maxit)
  count =3D count + 1;
  xnew =3D eval(g);
  error =3D abs((xnew - x)/xnew) * 100;
  fprintf('%7g %10.4f %10.4f %10.4f  =
%10.4f\n',count,x,xnew,error,eval(f));
 =20
  %these 2 lines are added just to show the convergence graphically
  if count&gt;1;line([x x],[x xnew]);else;plot(x,eval(g),'r*');end
  line([x xnew],[xnew xnew]);pause
 =20
  x =3D xnew;
end

if count&lt;maxit
   fprintf('\nRoot is %g   Function at root is %g\n',x,eval(f))
   figure(1);plot(x,eval(f),'ro')
   figure(2);plot(x,eval(g),'ro')       % circle at root found
end


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

⌨️ 快捷键说明

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