Newton 's Divided Difference Interpolation 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 ; 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
< ? php function proterm ( $ i , $ value , $ x ) { $ pro = 1 ; for ( $ j = 0 ; $ j < $ i ; $ j ++ ) { $ pro = $ pro * ( $ value - $ x [ $ j ] ) ; } return $ pro ; } function dividedDiffTable ( $ x , & $ y , $ n ) { for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { for ( $ j = 0 ; $ j < $ n - $ i ; $ j ++ ) { $ y [ $ j ] [ $ i ] = ( $ y [ $ j ] [ $ i - 1 ] - $ y [ $ j + 1 ] [ $ i - 1 ] ) / ( $ x [ $ j ] - $ x [ $ i + $ j ] ) ; } } } function applyFormula ( $ value , $ x , $ y , $ n ) { $ sum = $ y [ 0 ] [ 0 ] ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { $ sum = $ sum + ( proterm ( $ i , $ value , $ x ) * $ y [ 0 ] [ $ i ] ) ; } return $ sum ; } function printDiffTable ( $ y , $ n ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { for ( $ j = 0 ; $ j < $ n - $ i ; $ j ++ ) { echo round ( $ y [ $ i ] [ $ j ] , 4 ) . " " ; } echo " " ; } } $ n = 4 ; $ y = array_fill ( 0 , 10 , array_fill ( 0 , 10 , 0 ) ) ; $ x = array ( 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 ; echo " Value at " ▁ . ▁ $ value ▁ . ▁ " is " round ( applyFormula ( $ value , $ x , $ y , $ n ) , 2 ) . " STRNEWLINE " ? >