📄 simptol.mht
字号:
From: <Saved by Windows Internet Explorer 7>
Subject:
Date: Tue, 12 May 2009 09:51:46 -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/simptol.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>function [z, n] =3D simptol(func,a,b,tol)
% Routine for Simpson's 1/3 rule integration to specified tolerance.
%
% USAGE: [z, n] =3D traptol('function',a,b,tol)
%
% input: function =3D name of external function file. This file
% must be able to receive a vector of x data as input=20
% and produce a vector of y data as output
% a, b =3D limits of integration
% tol =3D absolute error tolerance in answer
% output: z =3D value of integral of function between a and b
% n =3D number of intervals required to obtained desired =
accuracy
% NOTE: in this routine n refers to the number of segments in the
% interval from a to b
% first integral using 2 segments
n =3D 2;
h =3D (b-a)/n;
x =3D linspace(a,b,n+1);
y =3D feval(func,x);
z1 =3D h*simpson(y);
abserror =3D Inf;
% start looping with doubled N
while abserror > tol
n =3D 2*n;
h =3D (b-a)/n;
x =3D linspace(a,b,n+1);
y =3D feval(func,x);
z2 =3D h*simpson(y);
abserror =3D abs(z2 - z1);
z1 =3D z2; % store this for next loop
end
z =3D z2;
</PRE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -