File Exchange

image thumbnail

Simpson's rule for numerical integration

version 1.5.0.0 (2.48 KB) by Damien Garcia
The Simpson's rule uses parabolic arcs instead of the straight lines used in the trapezoidal rule

59 Downloads

Updated 22 May 2013

View Version History

View License

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 different from one, multiply Z by the spacing increment.

Z = SIMPS(X,Y) computes the integral of Y with respect to X using the Simpson's rule.

Z = SIMPS(X,Y,DIM) or SIMPS(Y,DIM) integrates across dimension DIM

SIMPS uses the same syntax as TRAPZ.

Example:
-------
% The integral of sin(x) on [0,pi] is 2
% Let us compare TRAPZ and SIMPS
x = linspace(0,pi,6);
y = sin(x);
trapz(x,y) % returns 1.9338
simps(x,y) % returns 2.0071

Cite As

Damien Garcia (2020). Simpson's rule for numerical integration (https://www.mathworks.com/matlabcentral/fileexchange/25754-simpson-s-rule-for-numerical-integration), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (14)

Cemalettin Erdogan

Robert Newby

Sarthak Yadav

Andy Daubenspeck

Very useful, thanks!

Armindo

You have a cumulative version here in this pack
https://www.mathworks.com/matlabcentral/fileexchange/66494-fdasrvf

function name: cumsimps

which is also from the Damien Garcia

Tatsuya

Would be interested in a cumulative version, cumsimps, similar to cumtrapz.

emjey

Amin Mohammed

Excellent job, I hope Matlab will include this as a built-in function in future releases :)

David MERCIER

Nicholas Tavares

I am confused on how to use this I'm having the same problem as fernando

fernando

its very simple,and now i understand the trapz code but then the simps seems to not work on me ..it says
"Undefined function or method 'simps' for input arguments of
type 'double'." how can i fix this?

Matthew

Angelos

That is a very good example for the for understand the Simpson's rule!! Excellent work!

Danny Sale

This is a great extension of Simpson's rule. I find it most valuable that this file works correctly for both even and odd length vectors, and that it can correctly handle arbitrary spacing. Also, the method is fully vectorized so it is very fast. Thank you and excellent work!

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!