Code covered by the BSD License  

Highlights from
Simpson's numerical integration

5.0

5.0 | 1 rating Rate this file 26 Downloads (last 30 days) File Size: 4.14 KB File ID: #25754
image thumbnail

Simpson's numerical integration

by Damien Garcia

 

05 Nov 2009 (Updated 20 Nov 2009)

The Simpson's rule uses parabolic arcs instead of the straight lines used in the trapezoidal rule

| Watch this File

File Information
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 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 = CUMSIMPS(Y) computes an approximation of the cumulative integral of Y via the Simpson's method (with unit spacing).
 
Z = CUMSIMPS(X,Y) computes the cumulative integral of Y with respect to X using Simpson's integration.

SIMPS and CUMSIMPS use the same syntaxes as TRAPZ and CUMTRAPZ, respectively

Enter "help simps" and "help cumsimps" in the Matlab command window for complete information.

Examples:
--------
% 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

% The integral of cos(x) is sin(x)
% Let us compare CUMTRAPZ and CUMSIMPS
x = linspace(0,2*pi,20);
y = cos(x);
yt = cumtrapz(x,y);
ys = cumsimps(x,y);
% RMSE: root mean squared errors:
sqrt(mean((yt-sin(x)).^2)) % returns 0.0063
sqrt(mean((ys-sin(x)).^2)) % returns 1.2309e-004

------
Other examples are given in:
http://www.biomecardio.com/matlab/simps.html
http://www.biomecardio.com/matlab/cumsimps.html
-----

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
30 Aug 2011 Danny

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!

Please login to add a comment or rating.
Updates
20 Nov 2009

Minor modifications in the descriptions and help texts of the two functions.

Contact us at files@mathworks.com