To Compute the Value of Integration Using Simpson's 3/8th Method of Numerical Integration - C Data Structure

C examples for Data Structure:Algorithm

Description

To Compute the Value of Integration Using Simpson's 3/8th Method of Numerical Integration

Demo Code

#include<stdio.h>
#define MAX 50/*from   w  ww . j a  va 2s  .com*/

float simpson(float x){
    return (1/(1+x*x));
}

int main(){
  int i, j, num;
  float a, b, h, x[MAX], y[MAX], sum, result = 1;
  printf("\nIntegrand:  f(x) = 1/(1+x*x) \n");
  
  a = 7;

  b = 9;

  num = 30;
  h = (b - a)/num;
  sum = 0;
  sum = simpson(a) + simpson(b);
  for(i=1; i < num; i++) {
    if(i%3 == 0) {
      sum += 2*simpson(a + i*h);
    }
    else {
      sum += 3*simpson(a + i*h);
    }
  }
  result = sum * 3 * h / 8;
  printf("\nValue of Integration : %5.3f", result);
}

Related Tutorials