Numerical Integration (Simpsons 1/3 Rule) implementation in c programming.

Simpson's 1/3 Rule

Simpson’s 1/3 rule is based on approximating the integrand by a second order polynomial .It is an extension of Trapezoidal rule where, the trapezoidal rule was based on approximating the integrand by a first order polynomial, and then integrating the polynomial over interval of integration.

It calculates the value of the area under any curve over a given interval by dividing the area into equal parts. It follows the method similar to integration by parts.  It is used to estimate the value of a definite integral.

In order to integrate any function f(x) in the interval (a,b), follow the steps given below:
Ø  Select a value for n, which is the number of parts the interval is divided into. Let the value of n be an even number.
Ø  Calculate the width, h = (b−a) / n.
Ø  Calculate the values of x0 to xn as x0 = a, x1 = x0+ h, x n-1 = xn-2 + h, xn = b.
Ø  Consider y = f(x). Now find the values of y (y0 to yn) for the corresponding x(x0 to xn) values.
Ø  Substitute all the above found values in the Simpson's Rule Formula to calculate the integral value.

The code for Simpson’s 1/3 rule implementing in C is given below:
float f(float x)
void main()
   int i,n;
   float x0,xn,h,y[20],so,se,ans,x[20];
   printf("\n Enter values of x0,xn,h: ");
   printf("\n Refined value of n and h are:%d %f\n",n,h);
   printf("\n Y values: \n");
   for(i=0; i<=n; i++)
       printf("\n %f\n",y[i]);
   for(i=1; i<n; i++)

   printf("\n Final integration is %f",ans);


Input & Output:

In numerical analysis, Simpson's rules are used in Ship Stability and naval architecture, to calculate the areas and volumes of irregular figures. This rule is also used in computer engineering .It provides the exact result for a quadratic function or parabola.

Numerical Integration (Simpsons 1/3 Rule).Simpson's 1/3 Rule implementation in c programming.