# LaVOZs

The World’s Largest Online Community for Developers

'; python - Recursively find the nth order derivative with autograd grad() - LavOzs.Com

I am trying to find the nth derivative of a function using the grad function from the autograd library. grad(x) gives the 1st order derivative, but it doesn't allow a variable to find let's say the 3rd order derivative etc. Is there a way I might be able to do this recursively so the user can ender the derivative order they want to see?

``````import matplotlib.pyplot as plt

# a named Python function
g = lambda w: w**2

w_vals = np.linspace(-5,5,200)
nabla_g = grad(g)   #A function here that can find the nth derivative
# evaluate gradient over input range
g_vals = [g(v) for v in w_vals]
grad_vals = [nabla_g(v) for v in w_vals]
``````

``````# import matplotlib.pyplot as plt

for i in range(ord):
return fun

# a named Python function
g = lambda w: w**3

# derivative x^3 = 3x^2
# derivative 3x^2 = 6x
# derivative 6x = 6
w_vals = np.linspace(-5,5,200)
``````def my_grad(fun, ord):