Simpson's 3/8 rule can be used for numerical integration. Here is a matlab code to do so:
main.m163 chars8 lines
To use the above function for numerical integration, simply pass the function that needs to be integrated, and the limits of integration as inputs to the function. The output will be the numerical approximation of the integral.
For example, let's say we want to find the numerical approximation of the integral of sin(x)
from 0
to pi/2
. We can call the simpson38_rule
function as follows:
main.m71 chars5 lines
Therefore, the numerical approximation of the integral of sin(x)
from 0
to pi/2
using Simpson's 3/8 rule is approximately 0.9998
.
gistlibby LogSnag