• Recent Uploads

    NEWTON'S BACKWARD INTERPOLATION FORMULA IN C++ & WITH EXPLANATION

    Backward Interpolation.Interpolation is the technique of estimating the value of a function for any intermediate value of the independent variable, while the process of computing the value of the function outside the given range is called extrapolation.




    
    
    
    

    newtons backword interpolation formula

    // CPP Program to interpolate using // newton backward interpolation #include <bits/stdc++.h>
    using namespace std; // Calculation of u mentioned in formula float backward(float u, int n) { float temp = u; for (int i = 1; i < n; i++) temp = temp * (u + i); return temp; } // Calculating factorial of given n int fact(int n) { int f = 1; for (int i = 2; i <= n; i++) f *= i; return f; } int main() { // number of values given int n = 5; float x[] = { 1900,1910,1920,1930,1940,1950}; //input the values in tale float y[n][n]; y[0][0] = 65; y[1][0] = 76; y[2][0] = 91; y[3][0] = 97; y[4][0] = 110; // code for to display difference table for (int i = 1; i < n; i++) { for (int j = n - 1; j >= i; j--) y[j][i] = y[j][i - 1] - y[j - 1][i - 1]; } // Displaying difference table for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) cout << setw(4) << y[i][j] << "\t"; cout << endl; } float value = 1945; //which we have to interpolate float sum = y[n - 1][0]; float u = (value - x[n - 1]) / (x[1] - x[0]); for (int i = 1; i < n; i++) { sum = sum + (backward(u, i) * y[n - 1][i]) / fact(i); } cout << "\n Value at " << value << " is " << sum << endl; return 0; }
    OUTPUT 




    this progaran is running through the codechef ide