numericalderivative.FunctionWithArguments¶
- class numericalderivative.FunctionWithArguments(function, args=None)¶
Evaluate a function with extra arguments.
- Parameters:
- functionfunction
The function to differentiate.
- argslist
A list of optional arguments that the function takes as inputs. By default, there is no extra argument and calling sequence of the function must be y = function(x). If there are extra arguments, then the calling sequence of the function must be y = function(x, arg1, arg2, ...) where arg1, arg2, ..., are the items in the args list.
- verbosebool, optional
Set to True to print intermediate messages.
Methods
__call__(x)Evaluates the function at point x
get_args()Return the extra arguments
Return the function
Returns the number of function evaluations.
- Returns:
- None.
Examples
Define and evaluate a function with arguments.
>>> import numericalderivative as nd >>> >>> def scaled_exp_with_2_args(x, alpha, beta): >>> return beta * np.exp(-x / alpha) >>> >>> alpha = 1.e6 >>> beta = 2.0 >>> args = [alpha, beta] >>> function = nd.FunctionWithArguments( ... scaled_exp_with_2_args, args >>> ) >>> y = function(x) >>> for i in range(10): >>> y = function(x) >>> counter = function.get_number_of_evaluations()
- __init__(function, args=None)¶
Methods
__init__(function[, args])get_args()Return the extra arguments
Return the function
Returns the number of function evaluations.
- get_args()¶
Return the extra arguments
- Returns:
- argslist
The arguments
- get_function()¶
Return the function
- Returns:
- functionfunction
The function
- get_number_of_evaluations()¶
Returns the number of function evaluations.
- Returns:
- number_of_evaluationsint
The number of function evaluations.