Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. void interpolacja();
  6.  
  7. int main()
  8. {
  9. interpolacja();
  10.  
  11. return 0;
  12. }
  13.  
  14. void interpolacja()
  15. {
  16. int n;
  17. double punkt;
  18.  
  19. cout<<"Podaj liczbe wezlow: "; cin>>n; cout<<endl;
  20. double T[n];
  21. double fi[n];
  22.  
  23. cout<<"Podaj liczby rosnace!"<<endl; cout<<endl;
  24.  
  25. for(int i=0;i<n;i++)
  26. {
  27. cout<<"Podaj wartosc x: ";
  28. cin>>T[i];
  29.  
  30. if(T[i]<T[i-1] && i>0)
  31. {
  32. cout<<"Podales zla liczbe!"<<endl<<"Podaj jeszcze raz:";
  33. cin>>T[i];
  34. cout<<endl;
  35. }
  36.  
  37. cout<<"Podaj wartosc y: ";
  38. cin>>fi[i];
  39. cout<<endl;
  40. }
  41.  
  42. cout<<"Podaj punkt do przyblizenia: "; cin>>punkt; cout<<endl;
  43.  
  44.  
  45. while(punkt<T[0] || punkt>T[n-1])
  46. {
  47. cout<<"Podales zly punkt. Liczba musi byc w przedziale <"<<T[0]<<","<<T[n-1]<<">"<<endl<<"Podaj jeszcze raz punkt w tym przedziale!"<<endl<<endl<<"Liczba: "; cin>>punkt; cout<<endl;
  48.  
  49. }
  50.  
  51.  
  52. double fajny,suma=0;
  53. for(int k=0;k<n;k++)
  54. {
  55.  
  56. fajny=1;
  57. for(int h=0;h<n;h++)
  58. {
  59.  
  60. if(h!=k) fajny*=((punkt-T[h])/(T[k]-T[h]));
  61. }
  62. fajny*=fi[k];
  63. suma+=fajny;
  64. }
  65. cout<<"Wynik: "<<suma;
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement