/************************ INTEGRATION FOR TABULAR DATA *****************/
#include<iostream.h>
#include<conio.h>
int main()
{
int n,i;
float x[10],f[10],h,sum=0,a;
clrscr();
cout<<"No of datas ? ";cin>>n;
cout<<"Enter datas : ";
for(i=0;i<n;i++)
cin>>x[i]>>f[i];
for(i=0;i<n;i++)
{
if(i==0||i==n-1)
sum+=f[i];
else
sum+=2*f[i];
}
h=x[1]-x[0];
cout<<"The value using trapezoide: "<<h*sum/2;
a=x[0];
sum=0;
while((a-h)<x[n])
{
sum+=(f[a]+4*f[a+h]+f[a+2*h]);
a+=2*h;
}
cout<<"\nThe value using simpsons 1/3 is : "<<h*sum/3;
getch();
return 0;
}
C C++ CODE : Numerical integration for tabular data
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment
Your Comment and Question will help to make this blog better...