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.68 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 (X.size() == 1) {
  15. return Y[l];
  16. } else if (X.size() == 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. vector<double> X1(X.begin(), X.end() - (i+1));
  54. vector<double> Y1(Y.begin(), Y.end() - (i+1));
  55. a=wspolczynnik_c(X1,Y1, 0, X1.size() - 1);
  56. cout<<a<<endl;
  57. C.push_back(a);
  58. }
  59. cout << "Interpolacja rzedu " << rzad << " dla podanych punktow wyglada nastepujaco: " << endl << C[C.size()-1];
  60. for(i=0;i<rzad;i++)
  61. {
  62. int x=0;
  63. cout << " + ";
  64. cout << C[C.size()-(i+2)];
  65. for(j=k;j>i;j--)
  66. {
  67. cout << "(X-" << X[x] << ")";
  68. x++;
  69. }
  70. k+=2;
  71. }
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement