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

📄 bisect.mht

📁 it is a very essential matlab code.
💻 MHT
字号:
From: <Saved by Windows Internet Explorer 7>
Subject: 
Date: Tue, 12 May 2009 09:43:13 -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/bisect.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>% Demonstration of Bisection Root Finding of a function
%
% The function is defined in the file 'fcn.m' as follows:
%      function y = fcn(x)
%      y = 9.8 * 68.1 * (1-exp(-10*x/68.1))/x - 40;

clear;   

      xl = input ('Enter lower bound of root bracket:  ');
      xu = input ('Enter upper bound of root bracket:  ');
maxerror = input ('Enter maximum error (percent):      ');
   maxit = input ('Enter maximum number of iterations: ');

fplot('fcn',[xl xu]); grid on; hold on;

count = 0;          % iteration counter
actual_error = 1;   % to force entry to while loop

fprintf('\n  #         xl         xu         xr      error\n\n');

% main loop until interval width small enough

while (actual_error &gt; maxerror) &amp; (count &lt; maxit)

  count = count + 1;
  xr = (xl + xu)/2;
  plot(xr,fcn(xr),'ro');

  if xr ~= 0                            % ~= not equal
    actual_error = abs((xu - xl)/(xu + xl)) * 100;
  end

  fprintf('%3g %10g %10g %10g %10.4f\n',count,xl,xu,xr,actual_error)

  test = fcn(xl) * fcn(xr);  % form test product

  if test == 0
    actual_error = 0;
  elseif test &lt; 0
    xu = xr;      % root is below xr
  else        % i.e. test &gt; 0
    xl = xr;      % root is above xr
  end

end

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

⌨️ 快捷键说明

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