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
def proterm ( i , value , x ) : NEW_LINE INDENT pro = 1 ; NEW_LINE for j in range ( i ) : NEW_LINE INDENT pro = pro * ( value - x [ j ] ) ; NEW_LINE DEDENT return pro ; NEW_LINE DEDENT def dividedDiffTable ( x , y , n ) : NEW_LINE INDENT for i in range ( 1 , n ) : NEW_LINE INDENT for j in range ( n - i ) : NEW_LINE INDENT y [ j ] [ i ] = ( ( y [ j ] [ i - 1 ] - y [ j + 1 ] [ i - 1 ] ) / ( x [ j ] - x [ i + j ] ) ) ; NEW_LINE DEDENT DEDENT return y ; NEW_LINE DEDENT def applyFormula ( value , x , y , n ) : NEW_LINE INDENT sum = y [ 0 ] [ 0 ] ; NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT sum = sum + ( proterm ( i , value , x ) * y [ 0 ] [ i ] ) ; NEW_LINE DEDENT return sum ; NEW_LINE DEDENT def printDiffTable ( y , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT for j in range ( n - i ) : NEW_LINE INDENT print ( round ( y [ i ] [ j ] , 4 ) , " TABSYMBOL " , end = " ▁ " ) ; NEW_LINE DEDENT print ( " " ) ; NEW_LINE DEDENT DEDENT n = 4 ; NEW_LINE y = [ [ 0 for i in range ( 10 ) ] for j in range ( 10 ) ] ; NEW_LINE x = [ 5 , 6 , 9 , 11 ] ; NEW_LINE y [ 0 ] [ 0 ] = 12 ; NEW_LINE y [ 1 ] [ 0 ] = 13 ; NEW_LINE y [ 2 ] [ 0 ] = 14 ; NEW_LINE y [ 3 ] [ 0 ] = 16 ; NEW_LINE y = dividedDiffTable ( x , y , n ) ; NEW_LINE printDiffTable ( y , n ) ; NEW_LINE value = 7 ; NEW_LINE print ( " Value at " , ▁ value , ▁ " is " , round ( applyFormula ( value , x , y , n ) , 2 ) ) NEW_LINE