# Computing gradients of vector fields?

Premise, I'm not working with special/general relativity, so it may be that the way the formalism is thought in SageMath does not fit perfectly my needs.

I'm trying to define vector and tensor fields in Euclidean space and then differentiate them. For example, I'm interested in calculating the gradient of a vector field, namely, the tensor field

$$T_{ij} = \frac{dv_i}{dx_j}$$

. However classes like EuclideanSpace only allow me to produce vector fields on which I can compute divergence and curl. Should I just create three scalar fields, one for each component, and go with that? Or are there ways to get nabla out as a vector and use it directly to operate on actual vectors and tensors (in which case I could use the tensor product, $T = nabla \otimes v$)?

edit retag close merge delete

Sort by » oldest newest most voted

You can get nabla via nabla = E.metric().connection(), where E is the Euclidean space; then you apply it to the vector v by nabla(v), not by means of the tensor product. Here is a full example:

sage: E.<x,y,z> = EuclideanSpace()
sage: v = E.vector_field(-y, x^2, 1+x*y)
sage: nabla = E.metric().connection()
sage: nabla
Levi-Civita connection nabla_g associated with the Riemannian metric g on the Euclidean space E^3
sage: t = nabla(v)
sage: t
Tensor field of type (1,1) on the Euclidean space E^3
sage: t[:]
[  0  -1   0]
[2*x   0   0]
[  y   x   0]

more

Thanks a lot! Another thing, if you know, is there a convenience method to create an identity tensor in EuclideanSpace?

E.tangent_identity_field() returns the identity tensor.