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

Simpson's One-Third Rule

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:


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.


Flowchart of Simpson's One-third rule

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.


#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)*/
 printf("\n\nEnter the lower limit : ");
 printf("\n\nEnter the upper limit : ");
 printf("\n\nEnter the interval : ");
 h=(b-a)/n;      /*step length*/
 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);

Compiler Window:

Compiler Window of Simpson's One Third Rule

Output Window:

Output Screen of Simpson's One Third Rule

Video Tutorial:

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