# Simpson's One-Third Method: Algortihm, Flowchart, Program in C

## What is Simpson's One-Third Rule?

It is a three point quadrature, i.e. n=2. Therefore, there are only 3 functional values, y0 = f(x0) = f(a), y1 = f(x0+h) = f(x1), and y2 = f(x0+2h) = f(xn) = f(b). Thus, b-a = xn-x0 = 2h. So the third and higher order differences are not possible. Substituting, n=2 in

and neglecting the third and higher order differences, we get,

This formula is called Simpson's One-Third Rule for numeral Integration.

## Computation Scheme:

If the range of integration [a,b] be divided into n=2m (even) equal sub-intervals by 2m+1 points namely, a=x0, x0+h, x0+2h, ..., x0+(2m-4)h, x0+(2m-3)h, x0+(2m-2)h, x0+(2m-1)h, x0+2mh = b = xn and the Simpson's One-Third Rule be applied in each of the m(=n/2) sub-intervals [x0,x0+2h], [x0+2h,x0+4h], [x0+4h,x0+6h], ..., [x0+(2m-4)h,x0+(2m-2)h] and [x0+(2m-2)h,x0+2mh], we get,

This formula is called Composite Simpson's One-Third Rule for numerical integration.

NOTE: Simpson's One-Third Rule gives us exact results for a polynomial of degree less than or equal to three.

## Algorithm and Flowchart:

### Algorithm:

STEP 1: Read N(even)(the number of intervals), A, B (the limits of the integral) STEP 2: Define F(X)
STEP 3: Compute H=(B-A)/N, the interval size and P= F(A)+F(B)
STEP 4: Initialize I=1 and M=4 and compute the sum P=P+M*F(A+I*H)
STEP 5: If I=N then print simp=H*P/3, the value of the integral and terminate the process, otherwise go to STEP 5.

STEP 6: Replace the sum P by P+M*F(A+I*H), I by I+1 and M by 6-M and go to STEP 3.

## Sample Program:

WAP in C to evaluate sqrt(1-x^3) integrated between 0 to 1 by Simpson's One-Third Rule, taking 6 equal intervals, correct up to six decimal places.

### Code:

``````#include<stdio.h>
#include<conio.h>
#include<math.h>           /*including the header files*/
float f(float x)
{
return (sqrt(1-pow(x,3)));    /*declaring the function f(x)*/
}
void main()
{
float a,b,h,y0,yn,s1=0,s2=0,s3=0;
int i,n;
float f(float);        /*calling function f(x)*/
clrscr();
printf("\n\nEnter the lower limit : ");
scanf("%f",&a);
printf("\n\nEnter the upper limit : ");
scanf("%f",&b);
printf("\n\nEnter the interval : ");
scanf("%d",&n);
h=(b-a)/n;      /*step length*/
y0=f(a);
yn=f(b);
for(i=1;i<n;i++)
if(i%2==0)
s1=s1+f(a+i*h);
else
s2=s2+f(a+i*h);    /*calculation of s1 and s2*/
s3=(h/3)*(y0+yn+(2*s1)+(4*s2));     /*working formula*/
printf("\n\nThe result is : %f",s3);
getch();
}
``````

## Video Tutorial:

Feel free to comment below if you are facing any problem while executing the program.