Simpson 1/3 Rule in MATLAB

1
3464

Named after mathematician Thomas Simpson, Simpson’s rule or method is a popular technique of numerical analysis for numerical integration of definite integrals. It forms the even number of intervals and fits the parabola in each pair of interval. The method also corresponds to three point Newton – Cotes Quadrature rule.

In earlier tutorials, we’ve already discussed a C program for Simpson’s 1/3 rule. Here, we are going to write a program for Simpson 1/3 rule in MATLAB, and go through its mathematical derivation and numerical example.

Derivation of Simpson 1/3 Rule:

Consider a polynomial equation f(x) = 0 which is to be numerically integrated as shown in the figure below:

Simpson Rule in MATLAB - Curve

In the figure, f(x) implies the actual existing curve and P(x) is parabolic approximation of between two intervals.

Assume, Initial value of abscissa, x0 = a and Final value of abscissa, xn  = b

Let m be a value of abscissa such that, m = ( a + b ) / 2

By using Lagrange Polynomial Interpolation, the expression for P(x) can be given as:

P(x) = f(a) [ (x-m) ( x-b ) ]/ [ (a-m) ( a-b)] + f(m) [(x-a) (x-b) ]/ [ (m – a) ( m – b) ]

            + f(b) [ (x – a) ( x – m ) ] / [ ( b – a ) ( b – m )]

Substitution of value of ‘m’ and integrating in the interval [a, b],

Simpson Rule in MATLAB - Formula

which is the required expression. The code of Simpson Rule in Matlab is based on this formula.

Simpson 1/3 Rule in MATLAB Code:

The above Matlab code is for Simpson’s 1/3 rule to evaluate the function f(x) = 2 + cos(2 ). If the code is to be used to evaluate the numerical integration of other integrands, the value of ‘f’ in the program can be modified as per requirement.

In this MATLAB program, the interval in which the numerical integration is to be carried out and the allowed error or tolerance are the input. After giving these inputs to the program, the value of numerical integration of the function is displayed on the screen.

A sample input/output screenshot of the program is given below:

Simpson Rule in MATLAB - Output

Numerical Example of Simpson 1/3 Rule:

Now, let’s analyze mathematically the above program of Simpson rule in Matlab using the same function and limits of integration. The question here is:

Evaluate the following integral by using Simpson 1/3 rule with m = 1 and 2.

Simpson Rule in MATLAB - Example

Solution:

The given integrand is : f(x) = 2 + cos(2  )

The graph of f(x) can be shown as:

Simpson Rule in MATLAB - Graph of f(x)
Graph of f(x)

When m =1, using the expression for Simpson’s 1/3 rule:

I =

Simpson Rule in MATLAB - 1st Iteration

When m =2

I =

Simpson Rule in MATLAB - 2nd iteration

which is nearly the same as the value obtained from Simpson’s Matlab program.

If you have any questions regarding Simpson’s rule/method, its Matlab code, or mathematical derivation, bring them up from the comments. You can find more Numerical Methods tutorial using Matlab here.

1 COMMENT

  1. I do not see many comments here, it means you have low visitors. I know how to make your page go viral. If you want to know simply search in google for:
    Kimting’s Method To Go Viral

LEAVE A REPLY

Please enter your comment!
Please enter your name here