aerosandbox.numpy.finite_difference_operators#

Module Contents#

Functions#

finite_difference_coefficients(x[, x0, derivative_degree])

Computes the weights (coefficients) in compact finite differece formulas for any order of derivative

aerosandbox.numpy.finite_difference_operators.finite_difference_coefficients(x, x0=0, derivative_degree=1)[source]#

Computes the weights (coefficients) in compact finite differece formulas for any order of derivative and to any order of accuracy on one-dimensional grids with arbitrary spacing.

(Wording above is taken from the paper below, as are docstrings for parameters.)

Modified from an implementation of:

Fornberg, Bengt, “Generation of Finite Difference Formulas on Arbitrarily Spaced Grids”. Oct. 1988. Mathematics of Computation, Volume 51, Number 184, pages 699-706.

PDF: https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf

More detail: https://en.wikipedia.org/wiki/Finite_difference_coefficient

Parameters:
  • derivative_degree (int) – The degree of the derivative that you are interested in obtaining. (denoted “M” in the

  • paper)

  • x (numpy.ndarray) – The grid points (not necessarily uniform or in order) that you want to obtain weights for. You must

  • in (provide at least as many grid points as the degree of the derivative that you're interested) –

    The order of accuracy of your derivative depends in part on the number of grid points that you provide. Specifically:

    order_of_accuracy = n_grid_points - derivative_degree

    (This is in general; can be higher in special cases.)

    For example, if you’re evaluating a second derivative and you provide three grid points, you’ll have a first-order-accurate answer.

    (x is denoted “alpha” in the paper)

  • 1. (plus) –

    The order of accuracy of your derivative depends in part on the number of grid points that you provide. Specifically:

    order_of_accuracy = n_grid_points - derivative_degree

    (This is in general; can be higher in special cases.)

    For example, if you’re evaluating a second derivative and you provide three grid points, you’ll have a first-order-accurate answer.

    (x is denoted “alpha” in the paper)

  • x0 (float) – The location that you are interested in obtaining a derivative at. This need not be on a grid point.

Return type:

numpy.ndarray

Complexity is O(derivative_degree * len(x) ^ 2)

Returns: A 1D ndarray corresponding to the coefficients that should be placed on each grid point. In other words, the approximate derivative at x0 is the dot product of coefficients and the function values at each of the grid points x.