Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. double f(int rzad,vector<double> C,double X)
  8. {
  9. double wynik;
  10.  
  11. }
  12. double wspolczynnik_c(vector<double> X,vector<double> Y)
  13. {
  14. if(X.size() == 1)
  15. {
  16. return Y[0];
  17. }
  18. else
  19. if(X.size() == 2)
  20. {
  21. return (Y[0] - Y[1])/(X[0] - X[1]);
  22. }
  23. else
  24. {
  25. vector<double> X1(X.begin(), X.end() - 1);
  26. vector<double> X2(X.begin() + 1, X.end());
  27. vector<double> Y1(Y.begin(), Y.end() - 1);
  28. vector<double> Y2(Y.begin() + 1, Y.end());
  29. return (wspolczynnik_c(X1,Y1) - wspolczynnik_c(X2,Y2))/(X[0] - X[X.size() - 1]);
  30. }
  31. }
  32.  
  33. int main()
  34. {
  35. vector<double> X;
  36. vector<double> Y;
  37. vector<double> C;
  38. int rzad,pkt,j,i=0,k=1;
  39. double a;
  40. cout << "Podaj ilosc punktow do interpolacji: " << endl;
  41. cin >> pkt;
  42. cout << "Podaj zakladany rzad funkcji: " << endl;
  43. cin >> rzad;
  44. for(pkt;pkt>0;pkt--)
  45. {
  46. cout << "Podaj X: "<<endl;
  47. cin >> a;
  48. X.push_back(a);
  49. cout << "Podaj f(" << X[i] << "): " << endl;
  50. cin >> a;
  51. Y.push_back(a);
  52. i++;
  53. }
  54. for(i=0;i<rzad;i++)
  55. {
  56. vector<double> X1(X.begin(), X.end() - (i+1));
  57. vector<double> Y1(Y.begin(), Y.end() - (i+1));
  58. a=wspolczynnik_c(X1,Y1);
  59. cout<<a<<endl;
  60. C.push_back(a);
  61. }
  62. cout << "Interpolacja rzedu " << rzad << " dla podanych punktow wyglada nastepujaco: " << endl << C[C.size()-1];
  63. for(i=0;i<rzad;i++)
  64. {
  65. int x=0;
  66. cout << " + ";
  67. cout << C[C.size()-(i+2)];
  68. for(j=k;j>i;j--)
  69. {
  70. cout << "(X-" << X[x] << ")";
  71. x++;
  72. }
  73. k+=2;
  74. }
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement