# Simpson 1/3 Rule – Numerical Integration with MATLAB

Simpson 1/3 rule is a numerical integration technique which give the better result than trapezoidal rule. It is applicable when the number of interval n is even. The Simpson 1/3 rule reduce the error than trapezoidal rule. 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 1/3 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

[katex display=true]\int_{a}^{b}\frac{1}{1+x^2}dx[/katex]

The formula of composite Simpson 1/3 rule is

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

where a=x0 and b=xn


% Numerical Method Simpson 1/3 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 2)=');

h=(b-a)/n;

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

simp=h*(f(a)+4*sum1+2*sum2+f(b))/3;

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