Bessel 's Interpolation | C # Program to interpolate using Bessel 's interpolation ; calculating u mentioned in the formula ; calculating factorial of given number n ; Driver code ; 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 ) ; if ( ( n % 2 ) > 0 ) origin for odd ; k = n / 2 - 1 ; origin for even ; Solving using bessel 's formula
class GFG { static double ucal ( double u , int n ) { if ( n == 0 ) return 1 ; double temp = u ; for ( int i = 1 ; i <= n / 2 ; i ++ ) temp = temp * ( u - i ) ; for ( int i = 1 ; i < n / 2 ; 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 ; } public static void Main ( ) { int n = 6 ; double [ ] x = { 25 , 26 , 27 , 28 , 29 , 30 } ; double [ , ] y = new double [ n , n ] ; 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 ( int i = 1 ; i < n ; i ++ ) for ( int j = 0 ; j < n - i ; j ++ ) y [ j , i ] = y [ j + 1 , i - 1 ] - y [ j , i - 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n - i ; j ++ ) System . Console . Write ( y [ i , j ] + " TABSYMBOL " ) ; System . Console . WriteLine ( " " ) ; } double value = 27.4 ; double sum = ( y [ 2 , 0 ] + y [ 3 , 0 ] ) / 2 ; int k ; k = n / 2 ; else double u = ( value - x [ k ] ) / ( x [ 1 ] - x [ 0 ] ) ; for ( int 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 ) ) ; } System . Console . WriteLine ( " Value ▁ at ▁ " + value + " ▁ is ▁ " + System . Math . Round ( sum , 5 ) ) ; } }