Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In SageMath Manifolds grad needs a scalar field as an argument, so you can't use the operation twice since the first application gives a vector field.

In symbolic computations you can use twice the corresponding operations diff or jacobian

f(x,y) = x^2+y^2
g(x,y)=f.diff()(x,y) # gradient
g(x,y)

(2*x, 2*y)

g.diff()(x,y)        # Hessian

[2 0]
[0 2]

Or

f=x^2+y^2
g=jacobian(f, (x,y)); g

[2*x 2*y]

jacobian(g,(x,y))

[2 0]
[0 2]

For completeness

f.gradient()

(2*x, 2*y)

f.hessian()

[2 0]
[0 2]