:py:mod:`pytanksim.utils.finitedifferences` =========================================== .. py:module:: pytanksim.utils.finitedifferences .. autoapi-nested-parse:: Module for calculating derivatives numerically. Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: pytanksim.utils.finitedifferences.pardev pytanksim.utils.finitedifferences.partial_derivative pytanksim.utils.finitedifferences.backdev pytanksim.utils.finitedifferences.backward_partial_derivative pytanksim.utils.finitedifferences.fordev pytanksim.utils.finitedifferences.forward_partial_derivative pytanksim.utils.finitedifferences.second_derivative pytanksim.utils.finitedifferences.secforder pytanksim.utils.finitedifferences.second_forward_derivative pytanksim.utils.finitedifferences.secbackder pytanksim.utils.finitedifferences.second_backward_derivative pytanksim.utils.finitedifferences.mixed_second_derivative .. py:function:: pardev(func, loc, stepsize) Calculate the first derivative using centered finite difference. This function in particular only works with functions which have only one argument. :param func: A function that takes in a floating point number and outputs a floating point number. :type func: Callable[[float], float] :param loc: Location where the first derivative is to be evaluated. :type loc: float :param stepsize: The stepsize for the finite difference approximation. :type stepsize: float :returns: The first derivative of `func` evaluated at `loc`. :rtype: float .. py:function:: partial_derivative(func, var, point, stepsize = 0.001) Calculate the first partial derivative using centered finite difference. This version of the function works for functions which have an arbitrary number of arguments (one or more). :param func: A function that outputs a floating point number, and has at least one argument which is a floating point number. :type func: Callable[... , float] :param var: The integer showing the input order of the independent variable with respect to which the derivative of `func` is to be approximated. It uses python's convention for indexing (i.e., it counts from 0, 1, 2, 3, ...). For example, if the function `func` has the following signature:: def some_function(x1, x2, x3): .... return y If we want to find the partial derivative w.r.t. `x3`, then `var` should be 2. :type var: int :param point: A list of input values for `func`. These input values indicate the locations where the partial derivative is to be evaluated. :type point: List :param stepsize: The stepsize for the finite difference approximation. The default is 1e-3. :type stepsize: float :returns: The first partial derivative of `func` w.r.t. the variable specified by `var` evaluated at `point`. :rtype: float .. py:function:: backdev(func, loc, stepsize) Calculate the first derivative using backwards finite difference. This function in particular only works with functions which have only one argument. :param func: A function that takes in a floating point number and outputs a floating point number. :type func: Callable[[float], float] :param loc: Location where the first derivative is to be evaluated. :type loc: float :param stepsize: The stepsize for the finite difference approximation. :type stepsize: float :returns: The first derivative of `func` evaluated at `loc`. :rtype: float .. py:function:: backward_partial_derivative(func, var, point, stepsize = 0.001) Find the first partial derivative using backwards finite difference. This version of the function works for functions which have an arbitrary number of arguments (one or more). :param func: A function that outputs a floating point number, and has at least one argument which is a floating point number. :type func: Callable[... , float] :param var: The integer showing the input order of the independent variable with respect to which the derivative of `func` is to be approximated. It uses python's convention for indexing (i.e., it counts from 0, 1, 2, 3, ...). For example, if the function `func` has the following signature:: def some_function(x1, x2, x3): .... return y If we want to find the partial derivative w.r.t. `x3`, then `var` should be 2. :type var: int :param point: A list of input values for `func`. These input values indicate the location where the partial derivative is to be evaluated. :type point: List :param stepsize: The stepsize for the finite difference approximation. The default is 1e-3. :type stepsize: float :returns: The first partial derivative of `func` w.r.t. the variable specified by `var` evaluated at `point`. :rtype: float .. py:function:: fordev(func, loc, stepsize) Calculate the first derivative using forwards finite difference. This function in particular only works with functions which have only one argument. :param func: A function that takes in a floating point number and outputs a floating point number. :type func: Callable[[float], float] :param loc: Location where the first derivative is to be evaluated. :type loc: float :param stepsize: The stepsize for the finite difference approximation. :type stepsize: float :returns: The first derivative of `func` evaluated at `loc`. :rtype: float .. py:function:: forward_partial_derivative(func, var, point, stepsize = 0.001) Find the first partial derivative using forwards finite difference. This version of the function works for functions which have an arbitrary number of arguments (one or more). :param func: A function that outputs a floating point number, and has at least one argument which is a floating point number. :type func: Callable[... , float] :param var: The integer showing the input order of the independent variable with respect to which the derivative of `func` is to be approximated. It uses python's convention for indexing (i.e., it counts from 0, 1, 2, 3, ...). For example, if the function `func` has the following signature:: def some_function(x1, x2, x3): .... return y If we want to find the partial derivative w.r.t. `x3`, then `var` should be 2. :type var: int :param point: A list of input values for `func`. These input values indicate the location where the partial derivative is to be evaluated. :type point: List :param stepsize: The stepsize for the finite difference approximation. The default is 1e-3. :type stepsize: float :returns: The first partial derivative of `func` w.r.t. the variable specified by `var` evaluated at `point`. :rtype: float .. py:function:: second_derivative(func, var, point, stepsize = 1e-06) Find the second partial derivative using centered finite difference. This version of the function works for functions which have an arbitrary number of arguments (one or more). :param func: A function that outputs a floating point number, and has at least one argument which is a floating point number. :type func: Callable[... , float] :param var: The integer showing the input order of the independent variable with respect to which the derivative of `func` is to be approximated. It uses python's convention for indexing (i.e., it counts from 0, 1, 2, 3, ...). For example, if the function `func` has the following signature:: def some_function(x1, x2, x3): .... return y If we want to find the second partial derivative w.r.t. `x3`, then `var` should be 2. :type var: int :param point: A list of input values for `func`. These input values indicate the location where the second partial derivative is to be evaluated. :type point: List :param stepsize: The stepsize for the finite difference approximation. The default is 1e-6. :type stepsize: float :returns: The second partial derivative of `func` w.r.t. the variable specified by `var` evaluated at `point`. :rtype: float .. py:function:: secforder(function, location, stepsize = 1e-06) Calculate the second derivative using forwards finite difference. This function in particular only works with functions which have only one argument. :param function: A function that takes in a floating point number and outputs a floating point number. :type function: Callable[[float], float] :param location: Location where the second derivative is to be evaluated. :type location: float :param stepsize: The stepsize for the finite difference approximation. The default is 1e-6. :type stepsize: float :returns: The second derivative of `function` evaluated at `location`. :rtype: float .. py:function:: second_forward_derivative(func, var, point, stepsize = 1e-06) Find the second partial derivative using forwards finite difference. This version of the function works for functions which have an arbitrary number of arguments (one or more). :param func: A function that outputs a floating point number, and has at least one argument which is a floating point number. :type func: Callable[... , float] :param var: The integer showing the input order of the independent variable with respect to which the derivative of `func` is to be approximated. It uses python's convention for indexing (i.e., it counts from 0, 1, 2, 3, ...). For example, if the function `func` has the following signature:: def some_function(x1, x2, x3): .... return y If we want to find the second partial derivative w.r.t. `x3`, then `var` should be 2. :type var: int :param point: A list of input values for `func`. These input values indicate the location where the second partial derivative is to be evaluated. :type point: List :param stepsize: The stepsize for the finite difference approximation. The default is 1e-6. :type stepsize: float :returns: The second partial derivative of `func` w.r.t. the variable specified by `var` evaluated at `point`. :rtype: float .. py:function:: secbackder(function, location, stepsize = 1e-06) Calculate the second derivative using backwards finite difference. This function in particular only works with functions which have only one argument. :param function: A function that takes in a floating point number and outputs a floating point number. :type function: Callable[[float], float] :param location: Location where the second derivative is to be evaluated. :type location: float :param stepsize: The stepsize for the finite difference approximation. The default is 1e-6. :type stepsize: float :returns: The first derivative of `function` evaluated at `location`. :rtype: float .. py:function:: second_backward_derivative(func, var, point, stepsize = 1e-06) Find the second partial derivative using backwards finite difference. This version of the function works for functions which have an arbitrary number of arguments (one or more). :param func: A function that outputs a floating point number, and has at least one argument which is a floating point number. :type func: Callable[... , float] :param var: The integer showing the input order of the independent variable with respect to which the derivative of `func` is to be approximated. It uses python's convention for indexing (i.e., it counts from 0, 1, 2, 3, ...). For example, if the function `func` has the following signature:: def some_function(x1, x2, x3): .... return y If we want to find the second partial derivative w.r.t. `x3`, then `var` should be 2. :type var: int :param point: A list of input values for `func`. These input values indicate the location where the second partial derivative is to be evaluated. :type point: List :param stepsize: The stepsize for the finite difference approximation. The default is 1e-6. :type stepsize: float :returns: The second partial derivative of `func` w.r.t. the variable specified by `var` evaluated at `point`. :rtype: float .. py:function:: mixed_second_derivative(func, var, point, stepsize = [1000.0, 0.0001]) Find the mixed second derivative using finite difference. This version of the function works for functions which have an arbitrary number of arguments (two or more). :param func: A function that outputs a floating point number, and has at least two arguments which are floating point numbers. :type func: Callable[... , float] :param var: A list of integers showing the input order of the two variables with respect to which the mixed second derivative of `func` is to be approximated. It uses python's convention for indexing (i.e., it counts from 0, 1, 2, 3, ...). For example, if the function `func` has the following signature:: def some_function(x1, x2, x3): .... return y If we want to find the mixed second partial derivative w.r.t. `x1` and `x3`, then `var` should be [0, 2]. :type var: List[int] :param point: A list of input values for `func`. These input values indicate the location where the mixed second partial derivative is to be evaluated. :type point: List :param stepsize: The stepsizes for the finite difference approximation. It is a list of two floating point numbers. The default is [1E3, 1E-4]. :type stepsize: List[float] :returns: The mixed second partial derivative of `func` w.r.t. the two variables specified by `var` evaluated at `point`. :rtype: float