Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <fstream>
- using namespace std;
- double f(double x) {return x*exp(-x);}
- int main()
- {
- double x[10], y[10], p , polinom, X;
- double const delta =1e-2;
- ifstream fin("лагранж вход.txt");
- ofstream fout("лагранж выход x.txt");
- ofstream fYout("лагранж выход y.txt");
- ofstream fbout("начальный у.txt");
- for(int i=0;i<10;i++)
- {
- fin>>x[i];
- }
- for(int i=0;i<10;i++)
- {
- y[i]=f(x[i]);
- fbout<<y[i]<<endl;
- }//до сих пор все правильно. в х и у просто числа.
- for(X=x[0];X<x[9];X+=delta)
- {
- for (int i=0;i<10;i++)
- {
- double p=1;
- for(int j=0;j<10;j++)
- {
- if(j!=i) p*=(X-x[j])/(x[i]-x[j]);
- polinom+=p*y[i];
- }
- }
- fYout<<polinom<<endl;
- fout<<X<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement