Advertisement
MaPV

2VP_1_Lagranj

May 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <vector>
  3. #include <stdlib.h>
  4. #include "iostream"    
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main (){
  11. setlocale(LC_ALL,"ru");
  12. int N;
  13. double x;
  14. cout<<"введите количество узлов:";
  15. cin>>N;
  16.  
  17. double *X = new double[N]; //узлы  
  18. double *Y = new double[N];//значения
  19.  
  20. cout << "Ввод узлов Х:" << endl;
  21. for (int i = 0; i < N; i++){ cin >> X[i]; }
  22. cout << "Ввод значений Y :" << endl;
  23. for (int i = 0; i < N; i++){ cin >> Y[i]; }
  24. cout<<"в какой точке считем?";
  25. cin>>x;
  26. double up,down,Pn;
  27. up=1;
  28. Pn=0;
  29. for (int i = 0; i < N; i++){   //////почему не <=
  30.     up*=(x-X[i]);
  31. }; //wn(x)
  32.  
  33. for (int i = 0; i < N; i++){ //интерполяционный полином Лагранжа
  34. down=1;
  35.     for (int j = 0; j < N; j++){
  36.         if(j!=i) down*=(X[i]-X[j]);
  37. }
  38. Pn+=Y[i]*(up/((x-X[i])*down));
  39. }
  40. cout<<Pn<<endl;
  41. system("pause");
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement