MATH Lab- Double Integration using Trapezoidal Rule;

MATH Lab- Double Integration using Trapezoidal Rule of e^(x+y) from (0,1) & (-0.5,0.5);


#include<stdio.h>
#include<math.h>

double y(double x)
{
return (exp(x));
}

double integrate(double x,double x1,double n)
{
double h,ans=0;
h=((x1-x)/n);
int i;
for(i=0;i<=n;i++)
{
if(i==0 || i==n)
ans+=y((i*h)+x);
else
ans+=2*y((i*h)+x);
}
ans=ans*h/2;
return (ans);


}
main()
{
double ans=0;
ans=integrate(0,1,8);
ans*=integrate(-0.5,0.5,8);
printf("\nResult= %f\n",ans);

}



OUTPUT:-

-kkmohanta