Bessel 's Interpolation | Calculating u mentioned in the formula ; Calculating factorial of given number n ; Number of values given ; y is used for difference table with y [ 0 ] used for input ; Calculating the central difference table ; Displaying the central difference table ; Value to interpolate at ; Initializing u and sum ; k is origin thats is f ( 0 ) ; Origin for odd ; Origin for even ; Solving using bessel 's formula
function ucal ( u , n ) { if ( n == 0 ) return 1 ; var temp = u ; for ( var i = 1 ; i <= n / 2 ; i ++ ) temp = temp * ( u - i ) ; for ( var i = 1 ; i < n / 2 ; i ++ ) temp = temp * ( u + i ) ; return temp ; } function fact ( n ) { var f = 1 ; for ( var i = 2 ; i <= n ; i ++ ) f *= i ; return f ; } var n = 6 ; var x = [ 25 , 26 , 27 , 28 , 29 , 30 ] ; var y = Array ( n ) . fill ( 0.0 ) . map ( x => Array ( n ) . fill ( 0.0 ) ) ; ; y [ 0 ] [ 0 ] = 4.000 ; y [ 1 ] [ 0 ] = 3.846 ; y [ 2 ] [ 0 ] = 3.704 ; y [ 3 ] [ 0 ] = 3.571 ; y [ 4 ] [ 0 ] = 3.448 ; y [ 5 ] [ 0 ] = 3.333 ; for ( var i = 1 ; i < n ; i ++ ) for ( var j = 0 ; j < n - i ; j ++ ) y [ j ] [ i ] = y [ j + 1 ] [ i - 1 ] - y [ j ] [ i - 1 ] ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < n - i ; j ++ ) document . write ( y [ i ] [ j ] . toFixed ( 6 ) + " " ) ; document . write ( ' ' ) ; } var value = 27.4 ; var sum = ( y [ 2 ] [ 0 ] + y [ 3 ] [ 0 ] ) / 2 ; var k ; if ( ( n % 2 ) > 0 ) k = n / 2 ; else k = n / 2 - 1 ; var u = ( value - x [ k ] ) / ( x [ 1 ] - x [ 0 ] ) ; for ( var i = 1 ; i < n ; i ++ ) { if ( ( i % 2 ) > 0 ) sum = sum + ( ( u - 0.5 ) * ucal ( u , i - 1 ) * y [ k ] [ i ] ) / fact ( i ) ; else sum = sum + ( ucal ( u , i ) * ( y [ k ] [ i ] + y [ -- k ] [ i ] ) / ( fact ( i ) * 2 ) ) ; } document . write ( " " + value . toFixed ( 6 ) + " " + sum . toFixed ( 6 ) ) ;