Untitled

 avatar
unknown
plain_text
3 years ago
996 B
1
Indexable
#include <iostream>

using namespace std;

double zad1(){
    int n, p;
    cout<<"Podaj liczbe wezlow ";
    cin>>n;
    int x[n], y[n];
    for(int i = 0; i < n; i++){
        cout<<"Uzupelnij wezel numer "<<i<<endl;
        cin>>x[i];
    }
    for(int i = 0; i < n; i++){
        cout<<"Uzupelnij wartosc wezla numer "<<i<<endl;
        cin>>y[i];
    }
    cout<<"Podaj punkt p "<<endl;
    cin>>p;

    for( int i = 0; i < n; i++ )
    {
        for( int j = 0; j < n - 1; j++ )
        {
            if( x[ j ] > x[ j + 1 ] )
                 swap( x[ j ], x[ j + 1 ] );

        }
    }
    if(p >= x[0] && p < x[n]){
        double W[n + 1];
        for(int k = 0; k <= n; k++){
            W[k] = y[k];
            for(int j = k - 1; j >= 0; j--)
                W[j] = W[j + 1] + (W[j + 1] - W[j]) * (p - x[k]) / (x[k] - x[j]);
        }
        double wynik = W[0];
        return wynik;
    }
}

int main()
{
    cout<<"Wynik interpolacji Neville'a: "<<zad1()<<endl;
    return 0;
}
Editor is loading...