Newton Forward And Backward Interpolation | C # Program to interpolate using newton backward interpolation ; Calculation of u mentioned in formula ; Calculating factorial of given n ; Driver code ; number of values given ; y [ ] [ ] is used for difference table and y [ ] [ 0 ] used for input ; Calculating the backward difference table ; Displaying the backward difference table ; Value to interpolate at ; Initializing u and sum
using System ; class GFG { static double u_cal ( double u , int n ) { double temp = u ; for ( int i = 1 ; i < n ; i ++ ) temp = temp * ( u + i ) ; return temp ; } static int fact ( int n ) { int f = 1 ; for ( int i = 2 ; i <= n ; i ++ ) f *= i ; return f ; } static void Main ( ) { int n = 5 ; double [ ] x = { 1891 , 1901 , 1911 , 1921 , 1931 } ; double [ , ] y = new double [ n , n ] ; y [ 0 , 0 ] = 46 ; y [ 1 , 0 ] = 66 ; y [ 2 , 0 ] = 81 ; y [ 3 , 0 ] = 93 ; y [ 4 , 0 ] = 101 ; 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 ] ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) Console . Write ( y [ i , j ] + " TABSYMBOL " ) ; Console . WriteLine ( " " ) ; ; } double value = 1925 ; double sum = y [ n - 1 , 0 ] ; double u = ( value - x [ n - 1 ] ) / ( x [ 1 ] - x [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { sum = sum + ( u_cal ( u , i ) * y [ n - 1 , i ] ) / fact ( i ) ; } Console . WriteLine ( " STRNEWLINE ▁ Value ▁ at ▁ " + value + " ▁ is ▁ " + Math . Round ( sum , 4 ) ) ; } }