Nov 18, 2008

Trapezoidal Rule

Q.Integration of 1/(1+x^2) within the limit (1,6)


#include<stdio.h>

float f(float a)
{
float b;
b=(1/(1+(a*a)));
return b;
}

int main()
{
int i,m=1,n=6;
float y[7],z=0.0,w,h=1.0;
for(i=m;i<=n;i++)
{
y[i]=f(i);
printf("x=%d,y[%d]=%f\n",i,i,y[i]);
}

for(i=1;i<=n-1;i++)
{
z=z+y[i];
}
w=(((y[0]+y[n])+(2*z)));
printf("\nAns= %f\n",w);
return 0;
}

0 comments: