Skip to content
Advertisement

The gradient (2d) search function returns None. What is the problem?

I have a function that should return a gradient.

JavaScript

But when calculating the gradient at a specific point, I get None.

JavaScript

Object classes: t1-function, t2-function, t3-None (I want to get a two-dimensional point)

Please tell me how to change this line

JavaScript

to make it work?

PS. I understand that there are built-in methods for calculating the gradient. But this is a homework assignment in one of the courses. I would like to understand the error and do it according to the template.

PPS.This may be unnecessary, but I will give an example of a task for a single variable function that works as I expect.

JavaScript

and t3 is a number (dot), not None

Advertisement

Answer

In def grad_func(x), you don’t return anything. Inside that function, grad_func is a local variable. Consider writing that like:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement