Advertisement
Guest User

Untitled

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