Be the first to rate this file! 109 downloads (last 30 days) File Size: 4.14 KB File ID: #25754

Simpson's numerical integration

by Damien Garcia

 

05 Nov 2009 (Updated 20 Nov 2009)

Code covered by BSD License  

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

Download Now | 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)
Zip File Content  
Other Files cumsimps.m,
license.txt,
simps.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Updates
20 Nov 2009

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

 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com