Advertisement
Guest User

Untitled

a guest
May 26th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <vector>
  2. #include <fstream>
  3. #include <iostream>
  4. #include <cmath>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8. const int n=12,m=8;
  9.  
  10. void fun(double x[],double y[])
  11. {
  12. double a[8]={-2.04,0.854,0.44,0.21,5.96,-0.048,9.83,-0.264};
  13. for(int i=0;i<7;i++)
  14. {
  15. x[i]=a[i];
  16. y[i]=(exp(x[i])+exp((-1)*x[i]))/2;
  17. } //cos(x[i]);}
  18. }
  19.  
  20. double linInt(double x1, double x2, double y1, double y2, double z)
  21. {
  22. double a0, a1;
  23. a1=(y2-y1)/(x2-x1);
  24. a0=y1-x1*a1;
  25. return a1*z+a0;
  26. }
  27.  
  28. int main()
  29. {
  30. double h,a=0,b=2.0;
  31. double x[m],y[m],z[n],Lm[n];
  32. h=(b-a)/(n-1);
  33. cout<<setw(9)<<"x"<<setw(15)<<"y"<<setw(15)<<"f"<<endl;
  34. for(int j=0; j<n; j++)
  35. {
  36. fun(x,y); // vosstanovlenie y[i]
  37. z[j]=a+j*h; //promegutochnye tochki
  38. for(int k=1; k<m; k++)
  39. for(int i=m; i>=k; i--)
  40. y[i]=linInt(x[i-k],x[i],y[i-1],y[i],z[j]);
  41. Lm[j]=y[m];
  42. }
  43.  
  44. cout<<setw(9)<<"z"<<setw(15)<<"Lm"<<endl;
  45. for(int i=0; i<n; i++)
  46. 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])
  47. cin>> h;
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement