Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. double f(double x) {return x*exp(-x);}
  8. int main()
  9. {
  10.     double x[10], y[10], p , polinom, X;
  11.     double const delta =1e-2;
  12.     ifstream fin("лагранж вход.txt");
  13.     ofstream fout("лагранж выход x.txt");
  14.     ofstream fYout("лагранж выход y.txt");
  15.     ofstream fbout("начальный у.txt");
  16.     for(int i=0;i<10;i++)
  17.     {
  18.         fin>>x[i];
  19.     }
  20.     for(int i=0;i<10;i++)
  21.     {
  22.         y[i]=f(x[i]);
  23.         fbout<<y[i]<<endl;
  24.     }//до сих пор все правильно. в х и у просто числа.
  25.     for(X=x[0];X<x[9];X+=delta)
  26.     {
  27.        for (int i=0;i<10;i++)
  28.        {
  29.           double p=1;
  30.           for(int j=0;j<10;j++)
  31.            {
  32.              if(j!=i) p*=(X-x[j])/(x[i]-x[j]);
  33.              polinom+=p*y[i];
  34.            }
  35.         }
  36.     fYout<<polinom<<endl;
  37.     fout<<X<<endl;
  38.     }
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement