verry.autodiff.grad#
- verry.autodiff.grad(fun)#
Return a function that evaluates the gradient of the multivariate scalar-valued function.
- Parameters:
fun (Callable) – Diffarentiated function.
- Returns:
Gradient 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 gradient.
>>> from verry import FloatInterval as FI >>> from verry import function as vrf >>> f = lambda x, y: vrf.sqrt(x * y + 3) >>> df = grad(f) >>> c0 = df(0.5, 1.0) >>> print(format(c0[0], ".6g"), format(c0[1], ".6g")) 0.267261 0.133631
To obtain the value that accounts for rounding errors, pass intervals to df.
>>> c1 = df(FI("0.5"), FI("1")) >>> print(format(c1[0], ".6g")) [0.267261, 0.267262]