verry.autodiff.deriv#
- verry.autodiff.deriv(fun)#
Return a function that evaluates the derivative of the univariate scalar-valued function.
- Parameters:
fun (Callable) – Diffarentiated function.
- Returns:
Derivative of fun.
- Return type:
Callable
Warning
fun must neither be a constant nor contain conditional branches (cf. Common pitfalls).
Examples
This example computes a value of the derivative.
>>> from verry import FloatInterval as FI >>> from verry import function as vrf >>> f = lambda x: x**2 + vrf.sqrt(x + 3) >>> df = deriv(f) >>> c0 = df(1.2) >>> print(format(c0, ".6g")) 2.64398
To obtain the value that accounts for rounding errors, pass an interval to df.
>>> c1 = df(FI("1.2")) >>> print(format(c1, ".6g")) [2.64397, 2.64398]
Also, the second-order derivative can be obtained in the same way.
>>> ddf = deriv(df) >>> print(format(ddf(FI("1.2")), ".6g")) [1.97095, 1.97096]