(order, x_list, x0)
return delta
Calculates the finite difference weights for an arbitrarily
    spaced one-dimensional grid (x_list) for derivatives at 'x0'
    of order 0, 1, ..., up to 'order' using a recursive formula.

    Parameters
    ==========

    order : int
        Up to what derivative order weights should be calculated.
        0 corresponds to interpolation.
    x_list: sequence
        Strictly monotonically increasing sequence of values for
        the independent variable.
    x0: Number or Symbol
        At what value of the independent variable the finite difference
        weights should be generated.

    Returns
    =======

    list
        A list of sublists, each corresponding to coefficients for
        increasing derivative order, and each containing lists of
        coefficients for increasing accuracy.

    Examples
    ========

    >>> from sympy import S
    >>> from sympy.calculus import finite_diff_weights
    >>> finite_diff_weights(1, [-S(1)/2, S(1)/2, S(3)/2, S(5)/2], 0)
    [[[1, 0, 0, 0],
    [1/2, 1/2, 0, 0],
    [3/8, 3/4, -1/8, 0],
    [5/16, 15/16, -5/16, 1/16]],
    [[0, 0, 0, 0], [-1, 1, 0, 0], [-1, 1, 0, 0], [-23/24, 7/8, 1/8, -1/24]]]

    the result is two subslists, the first is for the 0:th derivative
    (interpolation) and the second for the first derivative (we gave
    1 as the parameter of order so this is why we get no list for
    a higher order derivative). Each sublist contains the most accurate
    formula in the end (all points used).

    Beware of the offset in the lower accuracy formulae when looking at a
    centered difference:

    >>> from sympy import S
    >>> from sympy.calculus import finite_diff_weights
    >>> finite_diff_weights(1, [-S(5)/2, -S(3)/2, -S(1)/2, S(1)/2,
    ...    S(3)/2, S(5)/2], 0) #doctest: +NORMALIZE_WHITESPACE
    [[[1, 0, 0, 0, 0, 0],
      [-3/2, 5/2, 0, 0, 0, 0],
      [3/8, -5/4, 15/8, 0, 0, 0],
      [1/16, -5/16, 15/16, 5/16, 0, 0],
      [3/128, -5/32, 45/64, 15/32, -5/128, 0],
      [3/256, -25/256, 75/128, 75/128, -25/256, 3/256]],
     [[0, 0, 0, 0, 0, 0],
      [-1, 1, 0, 0, 0, 0],
      [1, -3, 2, 0, 0, 0],
      [1/24, -1/8, -7/8, 23/24, 0, 0],
      [0, 1/24, -9/8, 9/8, -1/24, 0],
      [-3/640, 25/384, -75/64, 75/64, -25/384, 3/640]]]


    The capability to generate weights at arbitrary points can be
    used e.g. to minimize Runge's phenomenon by using Chebyshev nodes:

    >>> from sympy import cos, symbols, pi, simplify
    >>> from sympy.calculus import finite_diff_weights
    >>> N, (h, x) = 4, symbols('h x')
    >>> x_list = [x+h*cos(i*pi/(N)) for i in range(N,-1,-1)] # chebyshev nodes
    >>> print(x_list)
    [-h + x, -sqrt(2)*h/2 + x, x, sqrt(2)*h/2 + x, h + x]
    >>> mycoeffs = finite_diff_weights(1, x_list, 0)[1][4]
    >>> [simplify(c) for c in  mycoeffs] #doctest: +NORMALIZE_WHITESPACE
    [(h**3/2 + h**2*x - 3*h*x**2 - 4*x**3)/h**4,
    (-sqrt(2)*h**3 - 4*h**2*x + 3*sqrt(2)*h*x**2 + 8*x**3)/h**4,
    6*x/h**2 - 8*x**3/h**4,
    (sqrt(2)*h**3 - 4*h**2*x - 3*sqrt(2)*h*x**2 + 8*x**3)/h**4,
    (-h**3/2 + h**2*x + 3*h*x**2 - 4*x**3)/h**4]

    Notes
    =====

    If weights for a finite difference approximation
    of the 3rd order derivative is wanted, weights for 0th, 1st
    and 2nd order are calculated "for free", so are formulae using
    fewer and fewer of the paramters. This is something one can
    take advantage of to save computational cost.

    See also
    ========

    sympy.calculus.finite_diff.apply_finite_diff


    References
    ==========

    .. [1] Generation of Finite Difference Formulas on Arbitrarily Spaced
            Grids, Bengt Fornberg; Mathematics of compuation; 51; 184;
            (1988); 699-706; doi:10.1090/S0025-5718-1988-0935077-0
Calculates the finite difference weights for an arbitrarily
    spaced one-dimensional grid (x_list) for derivatives at 'x0'
    of order 0, 1, ..., up to 'order' using a recursive formula.
Calculates the finite difference weights for an arbitrarily spaced one - dimensional grid ( x_list ) for derivatives at x0 of order 0 1 ... up to order using a recursive formula .
def finite_diff_weights(order, x_list, x0):
    """
    Calculates the finite difference weights for an arbitrarily
    spaced one-dimensional grid (x_list) for derivatives at 'x0'
    of order 0, 1, ..., up to 'order' using a recursive formula.

    Parameters
    ==========

    order : int
        Up to what derivative order weights should be calculated.
        0 corresponds to interpolation.
    x_list: sequence
        Strictly monotonically increasing sequence of values for
        the independent variable.
    x0: Number or Symbol
        At what value of the independent variable the finite difference
        weights should be generated.

    Returns
    =======

    list
        A list of sublists, each corresponding to coefficients for
        increasing derivative order, and each containing lists of
        coefficients for increasing accuracy.

    Examples
    ========

    >>> from sympy import S
    >>> from sympy.calculus import finite_diff_weights
    >>> finite_diff_weights(1, [-S(1)/2, S(1)/2, S(3)/2, S(5)/2], 0)
    [[[1, 0, 0, 0],
    [1/2, 1/2, 0, 0],
    [3/8, 3/4, -1/8, 0],
    [5/16, 15/16, -5/16, 1/16]],
    [[0, 0, 0, 0], [-1, 1, 0, 0], [-1, 1, 0, 0], [-23/24, 7/8, 1/8, -1/24]]]

    the result is two subslists, the first is for the 0:th derivative
    (interpolation) and the second for the first derivative (we gave
    1 as the parameter of order so this is why we get no list for
    a higher order derivative). Each sublist contains the most accurate
    formula in the end (all points used).

    Beware of the offset in the lower accuracy formulae when looking at a
    centered difference:

    >>> from sympy import S
    >>> from sympy.calculus import finite_diff_weights
    >>> finite_diff_weights(1, [-S(5)/2, -S(3)/2, -S(1)/2, S(1)/2,
    ...    S(3)/2, S(5)/2], 0) #doctest: +NORMALIZE_WHITESPACE
    [[[1, 0, 0, 0, 0, 0],
      [-3/2, 5/2, 0, 0, 0, 0],
      [3/8, -5/4, 15/8, 0, 0, 0],
      [1/16, -5/16, 15/16, 5/16, 0, 0],
      [3/128, -5/32, 45/64, 15/32, -5/128, 0],
      [3/256, -25/256, 75/128, 75/128, -25/256, 3/256]],
     [[0, 0, 0, 0, 0, 0],
      [-1, 1, 0, 0, 0, 0],
      [1, -3, 2, 0, 0, 0],
      [1/24, -1/8, -7/8, 23/24, 0, 0],
      [0, 1/24, -9/8, 9/8, -1/24, 0],
      [-3/640, 25/384, -75/64, 75/64, -25/384, 3/640]]]


    The capability to generate weights at arbitrary points can be
    used e.g. to minimize Runge's phenomenon by using Chebyshev nodes:

    >>> from sympy import cos, symbols, pi, simplify
    >>> from sympy.calculus import finite_diff_weights
    >>> N, (h, x) = 4, symbols('h x')
    >>> x_list = [x+h*cos(i*pi/(N)) for i in range(N,-1,-1)] # chebyshev nodes
    >>> print(x_list)
    [-h + x, -sqrt(2)*h/2 + x, x, sqrt(2)*h/2 + x, h + x]
    >>> mycoeffs = finite_diff_weights(1, x_list, 0)[1][4]
    >>> [simplify(c) for c in  mycoeffs] #doctest: +NORMALIZE_WHITESPACE
    [(h**3/2 + h**2*x - 3*h*x**2 - 4*x**3)/h**4,
    (-sqrt(2)*h**3 - 4*h**2*x + 3*sqrt(2)*h*x**2 + 8*x**3)/h**4,
    6*x/h**2 - 8*x**3/h**4,
    (sqrt(2)*h**3 - 4*h**2*x - 3*sqrt(2)*h*x**2 + 8*x**3)/h**4,
    (-h**3/2 + h**2*x + 3*h*x**2 - 4*x**3)/h**4]

    Notes
    =====

    If weights for a finite difference approximation
    of the 3rd order derivative is wanted, weights for 0th, 1st
    and 2nd order are calculated "for free", so are formulae using
    fewer and fewer of the paramters. This is something one can
    take advantage of to save computational cost.

    See also
    ========

    sympy.calculus.finite_diff.apply_finite_diff


    References
    ==========

    .. [1] Generation of Finite Difference Formulas on Arbitrarily Spaced
            Grids, Bengt Fornberg; Mathematics of compuation; 51; 184;
            (1988); 699-706; doi:10.1090/S0025-5718-1988-0935077-0

    """
    # The notation below colosely corresponds that used in the paper.
    if order < 0:
        raise ValueError("Negtive derivative order illegal.")
    if int(order) != order:
        raise ValueError("Non-integer order illegal")
    M = order
    N = len(x_list) - 1
    delta = [[[0 for nu in range(N+1)] for n in range(N+1)] for
             m in range(M+1)]
    delta[0][0][0] = S(1)
    c1 = S(1)
    for n in range(1, N+1):
        c2 = S(1)
        for nu in range(0, n):
            c3 = x_list[n]-x_list[nu]
            c2 = c2 * c3
            if n <= M:
                delta[n][n-1][nu] = 0
            for m in range(0, min(n, M)+1):
                delta[m][n][nu] = (x_list[n]-x0)*delta[m][n-1][nu] -\
                    m*delta[m-1][n-1][nu]
                delta[m][n][nu] /= c3
        for m in range(0, min(n, M)+1):
            delta[m][n][n] = c1/c2*(m*delta[m-1][n-1][n-1] -
                                    (x_list[n-1]-x0)*delta[m][n-1][n-1])
        c1 = c2
    return delta
def finite_diff_weights ( order , x_list , x0 ) : # The notation below colosely corresponds that used in the paper. if order < 0 : raise ValueError ( "Negtive derivative order illegal." ) if int ( order ) != order : raise ValueError ( "Non-integer order illegal" ) M = order N = len ( x_list ) - 1 delta = [ [ [ 0 for nu in range ( N + 1 ) ] for n in range ( N + 1 ) ] for m in range ( M + 1 ) ] delta [ 0 ] [ 0 ] [ 0 ] = S ( 1 ) c1 = S ( 1 ) for n in range ( 1 , N + 1 ) : c2 = S ( 1 ) for nu in range ( 0 , n ) : c3 = x_list [ n ] - x_list [ nu ] c2 = c2 * c3 if n <= M : delta [ n ] [ n - 1 ] [ nu ] = 0 for m in range ( 0 , min ( n , M ) + 1 ) : delta [ m ] [ n ] [ nu ] = ( x_list [ n ] - x0 ) * delta [ m ] [ n - 1 ] [ nu ] - m * delta [ m - 1 ] [ n - 1 ] [ nu ] delta [ m ] [ n ] [ nu ] /= c3 for m in range ( 0 , min ( n , M ) + 1 ) : delta [ m ] [ n ] [ n ] = c1 / c2 * ( m * delta [ m - 1 ] [ n - 1 ] [ n - 1 ] - ( x_list [ n - 1 ] - x0 ) * delta [ m ] [ n - 1 ] [ n - 1 ] ) c1 = c2 return delta