Advertisement
Guest User

Untitled

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