5.1.6.6. numdifftools.nd_algopy.directionaldiff

directionaldiff(f, x0, vec, **options)[source]

Return directional derivative of a function of n variables

Parameters:
  • fun (callable) – analytical function to differentiate.

  • x0 (array) – vector location at which to differentiate fun. If x0 is an nxm array, then fun is assumed to be a function of n*m variables.

  • vec (array) – vector defining the line along which to take the derivative. It should be the same size as x0, but need not be a vector of unit length.

  • **options – optional arguments to pass on to Derivative.

Returns:

dder – estimate of the first derivative of fun in the specified direction.

Return type:

scalar

Examples

At the global minimizer (1,1) of the Rosenbrock function, compute the directional derivative in the direction [1 2]

>>> import numpy as np
>>> import numdifftools.nd_algopy as nda
>>> vec = np.r_[1, 2]
>>> rosen = lambda x: (1-x[0])**2 + 105*(x[1]-x[0]**2)**2
>>> dd = nda.directionaldiff(rosen, [1, 1], vec)
>>> np.allclose(dd, 0)
True

See also

Derivative, Gradient