Differentiating a multivariable function w.r.t different dimensions, using *args in python

  numerical-methods, python

Following is my attempt to create a function to differentiate multivariable functions, but as you see it only seems to be able to differentiate with respect to the first positional argument (namely x). How can I extend this to be able to take partial derivatives with respect to y and z?

def firstderivative(func,x,*args):
    return((func(x+0.001,*args)-func(x-0.001,*args))/0.002)
def afunc(x,y,z):
    return(x*y+x*z+y*z)
print(firstderivative(afunc,2,4,5))

Source: Python Questions

LEAVE A COMMENT