Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <fstream>
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- const int n=12,m=8;
- void fun(double x[],double y[])
- {
- double a[8]={-2.04,0.854,0.44,0.21,5.96,-0.048,9.83,-0.264};
- for(int i=0;i<7;i++)
- {
- x[i]=a[i];
- y[i]=(exp(x[i])+exp((-1)*x[i]))/2;
- } //cos(x[i]);}
- }
- double linInt(double x1, double x2, double y1, double y2, double z)
- {
- double a0, a1;
- a1=(y2-y1)/(x2-x1);
- a0=y1-x1*a1;
- return a1*z+a0;
- }
- int main()
- {
- double h,a=0,b=2.0;
- double x[m],y[m],z[n],Lm[n];
- h=(b-a)/(n-1);
- cout<<setw(9)<<"x"<<setw(15)<<"y"<<setw(15)<<"f"<<endl;
- for(int j=0; j<n; j++)
- {
- fun(x,y); // vosstanovlenie y[i]
- z[j]=a+j*h; //promegutochnye tochki
- for(int k=1; k<m; k++)
- for(int i=m; i>=k; i--)
- y[i]=linInt(x[i-k],x[i],y[i-1],y[i],z[j]);
- Lm[j]=y[m];
- }
- cout<<setw(9)<<"z"<<setw(15)<<"Lm"<<endl;
- for(int i=0; i<n; i++)
- cout<<setw(9)<<setprecision(4)<<z[i]<<setw(15)<<Lm[i]<<setw(15)<<(exp(z[i])+exp((-1)*z[i]))/2<<endl; //cos(z[i])
- cin>> h;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement