Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- void interpolacja();
- int main()
- {
- interpolacja();
- return 0;
- }
- void interpolacja()
- {
- int n;
- double punkt;
- cout<<"Podaj liczbe wezlow: "; cin>>n; cout<<endl;
- double T[n];
- double fi[n];
- cout<<"Podaj liczby rosnace!"<<endl; cout<<endl;
- for(int i=0;i<n;i++)
- {
- cout<<"Podaj wartosc x: ";
- cin>>T[i];
- if(T[i]<T[i-1] && i>0)
- {
- cout<<"Podales zla liczbe!"<<endl<<"Podaj jeszcze raz:";
- cin>>T[i];
- cout<<endl;
- }
- cout<<"Podaj wartosc y: ";
- cin>>fi[i];
- cout<<endl;
- }
- cout<<"Podaj punkt do przyblizenia: "; cin>>punkt; cout<<endl;
- while(punkt<T[0] || punkt>T[n-1])
- {
- 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;
- }
- double fajny,suma=0;
- for(int k=0;k<n;k++)
- {
- fajny=1;
- for(int h=0;h<n;h++)
- {
- if(h!=k) fajny*=((punkt-T[h])/(T[k]-T[h]));
- }
- fajny*=fi[k];
- suma+=fajny;
- }
- cout<<"Wynik: "<<suma;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement