Newton 's Divided Difference Interpolation Formula | C # program for implementing Newton divided difference formula ; Function to find the product term ; Function for calculating divided difference table ; Function for applying Newton 's  divided difference formula  ; Function for displaying divided difference table ; Driver Function ; number of inputs given ; y [ ] [ ] is used for divided difference table where y [ ] [ 0 ] is used for input ; calculating divided difference table ; displaying divided difference table ; value to be interpolated ; printing the value
using System ; class GFG { static float proterm ( int i , float value , float [ ] x ) { float pro = 1 ; for ( int j = 0 ; j < i ; j ++ ) { pro = pro * ( value - x [ j ] ) ; } return pro ; } static void dividedDiffTable ( float [ ] x , float [ , ] y , int n ) { for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < n - i ; j ++ ) { y [ j , i ] = ( y [ j , i - 1 ] - y [ j + 1 , i - 1 ] ) / ( x [ j ] - x [ i + j ] ) ; } } } static float applyFormula ( float value , float [ ] x , float [ , ] y , int n ) { float sum = y [ 0 , 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { sum = sum + ( proterm ( i , value , x ) * y [ 0 , i ] ) ; } return sum ; } static void printDiffTable ( float [ , ] y , int n ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n - i ; j ++ ) { Console . Write ( Math . Round ( y [ i , j ] , 4 ) + " TABSYMBOL ▁ " ) ; } Console . WriteLine ( " " ) ; } } public static void Main ( ) { int n = 4 ; float value ; float [ , ] y = new float [ 10 , 10 ] ; float [ ] x = { 5 , 6 , 9 , 11 } ; y [ 0 , 0 ] = 12 ; y [ 1 , 0 ] = 13 ; y [ 2 , 0 ] = 14 ; y [ 3 , 0 ] = 16 ; dividedDiffTable ( x , y , n ) ; printDiffTable ( y , n ) ; value = 7 ; Console . WriteLine ( " STRNEWLINE Value ▁ at ▁ " + ( value ) + " ▁ is ▁ " + Math . Round ( applyFormula ( value , x , y , n ) , 2 ) ) ; } }