#include<iostream>
#include<fstream>
#include<math.h>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
int main()
{
double x[100],y[100][100],h,term,t,xr,sum;
int i,n,j,k=0;
char filename[20];
cout<<"Give me the name of the output file name:";
cin>>filename;
ofstream f(filename);
std::ifstream input("input.txt");
cout<<"Give me the value of x in sin x";
cin>>xr;
while(!input.eof())
{
k=k+1;
input>>x[k]>>y[k][0];
}
n=k-1;
h=(x[2]-x[1]);
t=(xr-x[1])/h;
term=t;
sum=y[1][0];
for(i=1;i<=n;++i)
{
cout<<x[i]<<"\t"<<y[i][0]<<"\n";
}
for(i=1;i<=n;++i)
{
for(j=1;j<=n-i;++j)
{
y[j][i]=y[j+1][i-1]-y[j][i-1];
}
}
cout<<"The Difference Table is:\n";
f<<"The Difference Table is ::\n";
for(i=1;i<=n;++i)
{
cout<<setw(4)<<x[i]<<"\t";
f<<setw(4)<<x[i]<<"\t";
for(j=0;j<=n-i;++j)
{
cout<<setw(4)<<y[i][j]<<"\t";
f<<setw(4)<<y[i][j]<<"\t";
}
cout<<"\n";
f<<"\n";
}
for(i=1;i<n;++i)
{
sum=sum+y[1][i]*term;
term=term*(t-i)/(i+1);
}
cout<<"The Value of sin("<<xr<<")="<<sum;
f<<"The Value of sin("<<xr<<")="<<sum;
}
#include<fstream>
#include<math.h>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
int main()
{
double x[100],y[100][100],h,term,t,xr,sum;
int i,n,j,k=0;
char filename[20];
cout<<"Give me the name of the output file name:";
cin>>filename;
ofstream f(filename);
std::ifstream input("input.txt");
cout<<"Give me the value of x in sin x";
cin>>xr;
while(!input.eof())
{
k=k+1;
input>>x[k]>>y[k][0];
}
n=k-1;
h=(x[2]-x[1]);
t=(xr-x[1])/h;
term=t;
sum=y[1][0];
for(i=1;i<=n;++i)
{
cout<<x[i]<<"\t"<<y[i][0]<<"\n";
}
for(i=1;i<=n;++i)
{
for(j=1;j<=n-i;++j)
{
y[j][i]=y[j+1][i-1]-y[j][i-1];
}
}
cout<<"The Difference Table is:\n";
f<<"The Difference Table is ::\n";
for(i=1;i<=n;++i)
{
cout<<setw(4)<<x[i]<<"\t";
f<<setw(4)<<x[i]<<"\t";
for(j=0;j<=n-i;++j)
{
cout<<setw(4)<<y[i][j]<<"\t";
f<<setw(4)<<y[i][j]<<"\t";
}
cout<<"\n";
f<<"\n";
}
for(i=1;i<n;++i)
{
sum=sum+y[1][i]*term;
term=term*(t-i)/(i+1);
}
cout<<"The Value of sin("<<xr<<")="<<sum;
f<<"The Value of sin("<<xr<<")="<<sum;
}
I think it's very useful...
ReplyDelete