simps
Simpson's numerical integration
Contents
Download
Syntax
z = simps(y) z = simps(x,y) z = simps(...,dim)
Description
z = simps(y) computes an approximation of the integral of y via the Simpson's method (with unit spacing). To compute the integral for spacing other than one, multiply z by the spacing increment. Input y can be complex.
If y is a vector, simps(y) is the integral of y. If y is a matrix, simps(y) is a row vector with the integral over each column. If y is a multidimensional array, simps(y) works across the first nonsingleton dimension.
z = simps(x,y) computes the integral of y with respect to x using the Simpson's rule. Inputs x and y can be complex. If x is a column vector and y an array whose first nonsingleton dimension is length(x), simps(x,y) operates across this dimension.
z = simps(...,dim) integrates across the dimension of y specified by scalar dim. The length of x, if given, must be the same as size(y,dim).
Examples
Let us define by I the following integral:
Its exact value is 2. To approximate I numerically on a uniformly spaced grid, use
x = 0:pi/100:pi; y = sin(x);
Then both
I = simps(x,y);
and
I = pi/100*simps(y);
produce I = 2.000. In comparison, I = trapz(x,y) produces I = 1.9998.
This example uses complex inputs:
z = exp(1i*pi*(0:100)/100); simps(z,1./z)
ans = 0.0000 + 3.1416i
Information
Simpson's rule on Wolfram MathWorld.
See also
About the author
Damien Garcia, Eng., Ph.D. Assistant professor, Department of radiology CRCHUM, University of Montreal Hospital Montreal, QC, Canada Damien.Garcia.REMOVE-THIS@BiomeCardio.com