| MATLAB Function Reference | ![]() |
Numerically evaluate integral, adaptive Simpson quadrature
注意
The quad8 function, which implemented a higher order method, is
obsolete. The quadl function is its recommended replacement.
|
表示
q = quad(fun,a,b) q = quad(fun,a,b,tol) q = quad(fun,a,b,tol,trace) q = quad(fun,a,b,tol,trace,p1,p2,...)
詳細
q = quad(fun,a,b)
tries to approximate the integral of function fun from a to b within roundoff error using recursive adaptive Simpson quadrature. fun accepts a vector x and returns a vector y, the function fun evaluated at each element of x.
Quadrature is a numerical method used to find the area under the graph of a function, that is, to compute a definite integral.
q = quad(fun,a,b,tol)
uses an absolute error tolerance tol instead of the default which is
where
is the floating point accuracy eps and
is an estimate at the integral. Larger values of tol result in fewer function evaluations and faster computation, but less accurate results. In MATLAB version 5.3 and earlier, the quad function used a less reliable algorithm and a default relative tolerance of 1.0e-3.
q = quad(fun,a,b,tol,trace)
with non-zero trace shows the values of [fcnt a b-a Q] during the recursion.
provides for additional arguments q = quad(fun,a,b,tol,trace,p1,p2,...)
p1,p2,... to be passed directly to function fun, fun(x,p1,p2,...). Pass empty matrices for tol or trace to use the default values.
例題
例題 1. You can specify fun three different ways:
Q = quad('1./(x.^3-2*x-5)',0,2);
F = inline('1./(x.^3-2*x-5)');
Q = quad(F,0,2);
Q = quad(@myfun,0,2);
where myfun.m is an M-file.
function y = myfun(x) y = 1./(x.^3-2*x-5);
例題 2. Integrate the sine function from 0 to
:
a = quad(@sin,0,pi)
a =
2.0000
参考
dblquad, inline, quadl, @ (function handle)
参考文献
Forsythe, G.E., M.A. Malcolm and C.B. Moler, Computer Methods for Mathematical Computations, Prentice-Hall, 1977.
Gander, W. and W. Gautschi, "Adaptive Quadrature - Revisited", BIT, Vol. 40, 2000, pp. 84-101. This document is also available at http://www.inf.ethz.ch/personal/gander.
| qrupdate | quadl | ![]() |