| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
| On this page… |
|---|
The area beneath a section of a function F(x) can be determined by numerically integrating F(x), a process referred to as quadrature. The MATLAB quadrature functions are:
To integrate the function defined by humps.m from 0 to 1, use
q = quad(@humps,0,1)
q =
29.8583
Both quad and quadl operate recursively. If either method detects a possible singularity, it prints a warning.
You can include a fourth argument for quad or quadl that specifies an absolute error tolerance for the integration. If a nonzero fifth argument is passed to quad or quadl, the function evaluations are traced.
You can use quad or quadl to compute the length of a curve. Consider the curve parameterized by the equations
x(t) = sin(2t), y(t) = cos(t), z(t) = t,
where t ∊ [0,3π].
A three-dimensional plot of this curve is
t = 0:0.1:3*pi; plot3(sin(2*t),cos(t),t)
The arc length formula says the length of the curve is the integral of the norm of the derivatives of the parameterized equations
![]()
The function hcurve computes the integrand
function f = hcurve(t) f = sqrt(4*cos(2*t).^2 + sin(t).^2 + 1);
Integrate this function with a call to quad
len = quad(@hcurve,0,3*pi) len = 1.7222e+01
The length of this curve is about 17.2.
Consider the numerical solution of

For this example f(x,y) = ysin(x) + xcos(y). The first step is to build the function to be evaluated. The function must be capable of returning a vector output when given a vector input. You must also consider which variable is in the inner integral, and which goes in the outer integral. In this example, the inner variable is x and the outer variable is y (the order in the integral is dxdy). In this case, the integrand function is
function out = integrnd(x,y) out = y*sin(x) + x*cos(y);
To perform the integration, two functions are available in the funfun directory. The first, dblquad, is called directly from the command line. This M-file evaluates the outer loop using quad. At each iteration, quad calls the second helper function that evaluates the inner loop.
To evaluate the double integral, use
result = dblquad(@integrnd,xmin,xmax,ymin,ymax);
The first argument is a string with the name of the integrand function. The second to fifth arguments are
Lower limit of inner integral | |
Upper limit of the inner integral | |
Lower limit of outer integral | |
Upper limit of the outer integral |
Here is a numeric example that illustrates the use of dblquad.
xmin = pi; xmax = 2*pi; ymin = 0; ymax = pi; result = dblquad(@integrnd,xmin,xmax,ymin,ymax)
The result is -9.8698.
By default, dblquad calls quad. To integrate the previous example using quadl (with the default values for the tolerance argument), use
result = dblquad(@integrnd,xmin,xmax,ymin,ymax,[],@quadl);
Alternatively, you can pass any user-defined quadrature function name to dblquad as long as the quadrature function has the same calling and return arguments as quad.
![]() | Optimization | Differential Equations | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |