Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to find gradient of multiple variables at a given point?

I need to find gradient of function (x**2+y) at point [2, 4].

import numdifftools as nd
import sympy as sym
from sympy import *

x, y = sym.symbols('x y')

def rosen(x, y): 
    return (x**2 + y)
grad = nd.Gradient(rosen)([2, 4])
print("Gradient of is ", grad)
TypeError: rosen() missing 1 required positional argument: 'y'

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Argument to function passed to nd.Gradient must be an array.

import numdifftools as nd

def rosen(xy): 
    return (xy[0]**2 + xy[1])

grad = nd.Gradient(rosen)([2, 4])
print("Gradient of is ", grad)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading