I am trying to create simple code to identify critical points of a multivariate function. For pedagogical reasons, I want to do this completely manually. That is, I first want to compute the gradient, and then I want to solve for points where the gradient is zero. Here is my code:
var('x1 x2')
f(x1,x2) = x1^2 + x2^2
Df=f.derivative()
solve(Df(x1,x2)==(0,0),(x1,x2))
The third step returns what I want. If I evaluate Df(x1,x2)
, Sage returns (2*x1, 2*x2)
as expected. However the final step returns the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-33-bc76a33e3a15> in <module>
----> 1 solve(Df(x1,x2)==(Integer(0),Integer(0)),(x1,x2))
/var/tmp/sage-jc4b6yulaujayb9sr94ia88eourzeqip0oidmas3/local/lib/python3.8/site-packages/sage/symbolic/relation.py in solve(f, *args, **kwds)
1045
1046 if not isinstance(f, (list, tuple)):
-> 1047 raise TypeError("The first argument must be a symbolic expression or a list of symbolic expressions.")
1048
1049 # f is a list of such expressions or equations
TypeError: The first argument must be a symbolic expression or a list of symbolic expressions.