Numerical Program

Simpson 3/8 Rules Method Definition

Simpson's rule is a Newton-Cotes formula for approximating the integral of a function f using quadratic polynomials (i.e., parabolic arcs instead of the straight line segments used in the trapezoidal rule. Simpson's rule can be derived by integrating a third-order Lagrange interpolating polynomial fit to the function at three equally spaced points.

Program of Simpson 3/8 Rules in C language

   #include<stdio.h>
   #include<conio.h>
   #include<math.h>
   #define f(x) 1/(1+x);

   void main()
   {
    int n,i;
    float a,b,s,s1=0,s2=0,u,h,y;
    clrscr();
    
    printf("Enter the uper limit: ");
    scanf("%f",&a);
    printf("Enter the lower limit: ");
    scanf("%f",&b);
    printf("Enter the interval: ");
    scanf("%d",&n);
    h=(a-b)/n;
    s=f(a)+f(b);
    for(i=1;i<=n-1;i++)
    { if(i%3==0)
        {
            s1=s1+2*f(a+(i*h));
        }
        else
        {
            s2=s2+2*f(a+(i*h));
        }
        u=((3*h)/8)*(s+s1+s2);
    }
    printf("Answer is: %f",u);
    
    getch();
}
  

Output

Post Your Comment

Some Useful Tricks of Windows

Follow us on Facebook

Advertisement