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

📄 secant.mht

📁 it is a very essential matlab code.
💻 MHT
字号:
From: <Saved by Windows Internet Explorer 7>
Subject: 
Date: Tue, 12 May 2009 09:44:06 -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/secant.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 using Secant method
%
% The function is defined in another script file as follows:
% (Note that this won't accept vector inputs)
%
%   function y = fcn(x)
%       y = x^4 - 5*x^3 - 124*x^2 + 380*x + 1200;
clear; clf; 

% First, plot the function to estimate the root location
fplot('fcn',[1 20])
hold on

% now proceed with finding a root:

x1 = input('Enter first guess of root location: ');
x2 = input('Enter second guess of root location: ');

itermax = 100;      % max # of iterations
iter = 0;
errmax = 0.001;     % convergence tolerance
error = 1;
fprintf('\n   #      x1        x2       x3       rel error\n\n');

while error &gt; errmax &amp; iter &lt; itermax

  iter = iter + 1;
  f1 = fcn(x1);
  f2 = fcn(x2);

  x3 = x2 - f2*(x2-x1) / (f2 - f1);    % here is new root estimate
  plot(x3, fcn(x3),'ro')

  error = abs((x3 - x2)/x3) * 100;  % find change from previous

  fprintf('%3i %8g  %8g  %10.6f   %10.5f\n',iter,x1,x2,x3,error);
  x1 = x2;      % set up for next iteration
  x2 = x3;
end



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

⌨️ 快捷键说明

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