# How am I able to take the gradient of a symbolic function twice?

I have introduced a Euclidean space using

E.<x,y,z> = EuclideanSpace()


then defined a symbolic function using

f(x,y) = x^2 + y^2


then I introduce the manifold library and take the gradient

from sage.manifolds.operators import *


which give me the expected result, however if I try to take the gradient again, I am met with an error:

'FreeModule_ambient_field_with_category.element_class' object has no attribute 'gradient'

I have no idea what this means. I am not very experience with mathematical spaces and fields and all that fun stuff yet, so I was wondering if someone could help me understand what this means and how to get around it.

Thanks!

edit retag close merge delete

Sort by ยป oldest newest most voted

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)

(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]

more