Simpson 3/8 Rule – Numerical Integration with MATLAB

Simpson 3/8 rule is a numerical integration technique which give the better result than trapezoidal rule but error more than Simpson 1/3 rule. It is applicable when the number of interval multiple of 3n. The large number of interval give the best result and reduce error compare than small number of interval. This rule is also based on computing the area of trapezium.

At here, we write the code of Simpson 3/8 Rule in MATLAB step by step. MATLAB is easy way to solve complicated problems that are not solve by hand or impossible to solve at page. MATLAB is develop for mathematics, therefore MATLAB is the abbreviation of MATrix LABoratory.

In this program, we evaluate the integral

\int_{a}^{b}\frac{1}{1+x^2}dx

The formula of composite Simpson 1/3 rule is

\int_{a}^{b}f(x)dx=\frac{3h}{8}(f(x_0)+3\sum_{i=1}^{\frac{n}{3}}f(x_{3i-2})+3\sum_{i=1}^{\frac{n}{3}}f(x_{3i-1})+2\sum_{i=1}^{\frac{n}{3}-1}f(x_{3i})+f(x_n))

where a=x0 and b=xn


% Numerical Analysis Simpson 3/8 Rule using MATLAB
clear all;
close all;
clc;

f=inline('1/(1+x^2)');

a=input('Enter lower limit of integral=');
b=input('Enter upper limit of integral=');
n=input('Enter number of intervals (multiple of 3)=');

h=(b-a)/n;

sum1=0.0;
sum2=0.0;
sum3=0.0;

for i=1:3:n-2
    x=a+i*h;
    sum1=sum1+f(x);
end
for i=2:3:n-1
    x=a+i*h;
    sum2=sum2+f(x);
end
for i=3:3:n-3
    x=a+i*h;
    sum3=sum3+f(x);
end

simp=3*h*(f(a)+3.0*sum1+3.0*sum2+2.0*sum3+f(b))/8.0;

fprintf('Integrated value is %f',simp)