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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值