matlab的quadl函数,matlab quad 函数代码中的y(1) ,跟数值积分分成的n个节点有什么关系,...

matlab quad 函数代码中的y(1) ,跟数值积分分成的n个节点有什么关系,

matlab quad 函数代码中的y(1) ,跟数值积分分成的n个节点有什么关系,

function [Q,fcnt] = quad(funfcn,a,b,tol,trace,varargin)

%QUAD Numerically evaluate integral,adaptive Simpson quadrature.

% Q = QUAD(FUN,A,B) tries to approximate the integral of scalar-valued

% function FUN from A to B to within an error of 1.e-6 using recursive

% adaptive Simpson quadrature.FUN is a function handle.The function

% Y=FUN(X) should accept a vector argument X and return a vector result

% Y,the integrand evaluated at each element of X.

%

% Q = QUAD(FUN,A,B,TOL) uses an absolute error tolerance of TOL

% instead of the default,which is 1.e-6.Larger values of TOL

% result in fewer function evaluations and faster computation,

% but less accurate results.The QUAD function in MATLAB 5.3 used

% a less reliable algorithm and a default tolerance of 1.e-3.

%

% Q = QUAD(FUN,A,B,TOL,TRACE) with non-zero TRACE shows the values

% of [fcnt a b-a Q] during the recursion.Use [] as a placeholder to

% obtain the default value of TOL.

%

% [Q,FCNT] = QUAD(...) returns the number of function evaluations.

%

% Use array operators .*,./ and .^ in the definition of FUN

% so that it can be evaluated with a vector argument.

%

% Notes:

% Function QUADL may be more efficient with high accuracies and smooth

% integrands.

% Function QUADV vectorizes QUAD for array-valued FUN.

%

% Example:

% Q = quad(@myfun,0,2);

% where myfun.m is the M-file function:

% %-------------------%

% function y = myfun(x)

% y = 1./(x.^3-2*x-5);

% %-------------------%

%

% or,use a parameter for the constant:

% Q = quad(@(x)myfun2(x,5),0,2);

% where myfun2 is the M-file function:

% %----------------------%

% function y = myfun2(x,c)

% y = 1./(x.^3-2*x-c);

% %----------------------%

%

% Class support for inputs A,B,and the output of FUN:

% float:double,single

%

% See also QUADV,QUADL,DBLQUAD,TRIPLEQUAD,TRAPZ,FUNCTION_HANDLE.

% Based on "adaptsim" by Walter Gander.

%

% Reference:

% [1] W.Gander and W.Gautschi,Adaptive Quadrature - Revisited,

% BIT Vol.40,No.1,March 2000,pp.84-101.

%

% Copyright 1984-2006 The MathWorks,Inc.

% $Revision:5.26.4.7 $ $Date:2006/04/03 17:10:41 $

f = fcnchk(funfcn);

if nargin < 4 || isempty(tol),tol = 1.e-6; end;

if nargin < 5 || isempty(trace),trace = 0; end;

if isscalar(a) || isscalar(b)

error('MATLAB:quad:scalarLimits',...

'The limits of integration must be scalars.');

end

% Initialize with three unequal subintervals.

h = 0.13579*(b-a);

x = [a a+h a+2*h (a+b)/2 b-2*h b-h b];

y = f(x,varargin{:});

fcnt = 7;

% Fudge endpoints to avoid infinities.

if isfinite(y(1))

y(1) = f(a+eps(superiorfloat(a,b))*(b-a),varargin{:});

fcnt = fcnt+1;

end

if isfinite(y(7))

y(7) = f(b-eps(superiorfloat(a,b))*(b-a),varargin{:});

fcnt = fcnt+1;

end


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部