Code covered by the BSD License  

Highlights from
Simpson's Rule Integration

5.0

5.0 | 1 rating Rate this file 58 Downloads (last 30 days) File Size: 1.71 KB File ID: #28726

Simpson's Rule Integration

by Juan Camilo Medina

 

16 Sep 2010 (Updated 29 Apr 2011)

Computes an integral "I" via Simpson's rule in the interval [a,b] with n+1 equally spaced points

| Watch this File

File Information
Description

This function computes the integral "I" via Simpson's rule in the interval [a,b] with n+1 equally spaced points

Syntax: I = simpsons(f,a,b,n)

Where,
 f= can either be an anonymous function (e.g. f=@(x) sin(x)) or a vector containing equally spaced values of the function to be integrated
 a= Initial point of interval
 b= Last point of interval
 n= # of sub-intervals (panels), must be integer

Written by Juan Camilo Medina - The University of Notre Dame
 09/2010 (copyright Dr. Simpson)

Example 1:

Suppose you want to integrate a function f(x) in the interval [-1,1].
You also want 3 integration points (2 panels) evenly distributed through the
domain (you can select more point for better accuracy).
Thus:
f=@(x) ((x-1).*x./2).*((x-1).*x./2);
I=simpsons(f,-1,1,2)

Example 2:

Suppose you want to integrate a function f(x) in the interval [-1,1].
You know some values of the function f(x) between the given interval,
those are fi= {1,0.518,0.230,0.078,0.014,0,0.006,0.014,0.014,0.006,0}
Thus:
fi= [1 0.518 0.230 0.078 0.014 0 0.006 0.014 0.014 0.006 0];
I=simpsons(fi,-1,1,[])
note that there is no need to provide the number of intervals (panels) "n",
since they are implicitly specified by the number of elements in the vector fi

Acknowledgements

This file inspired Simpson's 1/3 And 3/8 Rules.

MATLAB release MATLAB 7.10 (R2010a)
Tags for This File  
Everyone's Tags
approximation(2), integration, mathematics, matlab, numerical methods, simpsons rule
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
09 Sep 2012 Ivan  
06 Jun 2011 shin

goddd

02 Nov 2010 Juan Camilo Medina

Feel free to leave your comments here.

Updates
22 Sep 2010

n/a

29 Sep 2010

.

01 Nov 2010

.

08 Apr 2011

I added an example

27 Apr 2011

Added an extension to handle vectors as well and anonymous function.

29 Apr 2011

.

Contact us