📄 oneptrx.mht
字号:
From: <Saved by Windows Internet Explorer 7>
Subject:
Date: Tue, 12 May 2009 09:44:24 -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/oneptrx.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 WITH RELAXATION
clear;
% define the function and its x =3D g(x) version
f =3D 'x^4 - 5*x^3 - 124*x^2 + 380*x + 1200';
% version 1 of g(x)
disp('Version 1 of g')
g =3D '-1200/(x^3 - 5*x^2 - 124*x + 380)';
% version 2 of g(x)
%disp('Version 2 of g')
%g =3D '(5*x^3 + 124*x^2 - 380*x - 1200)/x^3';
% version 3 of g(x)
%disp('Version 3 of g')
%g =3D '(-x^4 + 5*x^3 - 380*x - 1200)/(-124*x)';
x =3D input ('Enter initial guess of root : ');
W =3D input ('Enter relaxation factor W : ');
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 > maxerror) & (count < maxit)
count =3D count + 1;
temp =3D eval(g);
xnew =3D x + W*(temp - x);
error =3D abs((xnew - x)/xnew) * 100;
fprintf('%7g %10.4f %10.4f %10.4f =
%10.4f\n',count,x,xnew,error,eval(f));
x =3D xnew;
end
fprintf('\nRoot is %g Function at root is %g\n',x,eval(f))
</PRE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -