📄 incsrch.mht
字号:
From: <Saved by Windows Internet Explorer 7>
Subject:
Date: Tue, 12 May 2009 09:42:55 -0700
MIME-Version: 1.0
Content-Type: text/html;
charset="Windows-1252"
Content-Transfer-Encoding: 7bit
Content-Location: http://www.mece.ualberta.ca/Courses/mec390/390code/incsrch.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=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.6000.16825" name=GENERATOR></HEAD>
<BODY><PRE>% root finding by incremental search
%
% This uses the external function func1.m defined as follows
%
% function f = func1(x)
% f = (x-4)*(x-10)*(x-20) + 1;
%
% This has roots near x = 4, 10, 20
clear
% get a quick plot of the function
xp = linspace(0,25);
yp = func1(xp);
plot(xp,yp)
x = input('Enter starting x value :');
xinc = input('Enter x increment :');
eps = input('Enter desired absolute accuracy :');
false = 0;
true = 1;
found = false;
while found == false
xup = x + xinc;
flow = func1(x);
fup = func1(xup);
if flow == 0 | fup == 0
found = true;
elseif flow*fup < 0
fprintf('root between %g and %g\n',x,xup)
if xinc < eps
found = true;
else
xinc = xinc / 10;
fprintf('Changing increment to %g\n\n',xinc)
end
else
x = xup;
end
end
x
flow
xup
fup
</PRE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -