Advertisement
szmelu

Iterpolacja

Mar 6th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. #include <fstream>
  5. #include <cstdlib>
  6. #include <ctime>
  7. using namespace std;
  8. void interpolacja(double x, int ilosc, double *tab, double *tab1)
  9. {
  10.  
  11. double *l = new double[ilosc];
  12. for (int i = 0; i < ilosc; i++)
  13. {
  14. if (i == ilosc-2)
  15. {
  16. l[i] = ((x - tab[i + 1]) / (tab[i] - tab[i + 1]))*((x - tab[0]) / (tab[i ] - tab[0]));
  17. }
  18. else if (i == ilosc - 1)
  19. {
  20. l[i] = ((x - tab[0]) / (tab[i] - tab[0]))*((x - tab[1]) / (tab[i] - tab[1]));
  21. }
  22. else
  23. {
  24. l[i] = ((x - tab[i + 1]) / (tab[i] - tab[i + 1]))*((x - tab[i + 2]) / (tab[i] - tab[i + 2]));
  25. }
  26.  
  27. }
  28. double L = 0;
  29. for (int i = 0; i < ilosc; i++)
  30. {
  31. L = L + (tab1[i] * l[i]);
  32. }
  33. cout <<"L(x) = "<< L << endl;;
  34. }
  35. int main()
  36. {
  37. cout << "Wprowadz dla jakiej wartosci znalezc interpolacje: ";
  38. double x;
  39. cin >> x;
  40. int ilosc = 3;
  41. double *tab = new double[ilosc];
  42. double *tab1 = new double[ilosc];
  43. tab[0] = 1;
  44. tab[1] = 3;
  45. tab[2] = 5;
  46. tab1[0] = 12;
  47. tab1[1] = 4;
  48. tab1[2] = 4;
  49. interpolacja(x, ilosc, tab, tab1);
  50.  
  51.  
  52. system("pause");
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement