central_difference

despasito.utils.general_toolbox.central_difference

central_difference(x, func, step_size=1e-05, relative=False, args=())[source]

Take the derivative of a dependent variable calculated with a given function using the central difference method.

Parameters:
  • x (numpy.ndarray) – Independent variable to take derivative with respect too, using the central difference method. Must be first input of the function.

  • func (function) – Function used in job to calculate dependent factor. This function should have a single output.

  • step_size (float, Optional, default=1E-5) – Either the step size used in the central difference method, or if relative=True, this variable is a scaling factor so that the step size for each value of x is x * step_size.

  • args (tuple, Optional, default=()) – Each entry of this list contains the input arguments for each job

  • relative (bool, Optional, default=False) – If False, the step_size is directly used to calculate the derivative. If true, step_size becomes a scaling factor, where the step size for each value of x becomes step_size*x.

Returns:

dydx – Array of derivative of y with respect to x, given an array of independent variables.

Return type:

numpy.ndarray