Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

grad on a generic metric

Hi.

First, thank you for SageMath Manifolds! I find it fascinating. I am a newbie, and I have indeed looked through the forum and the documentation, but am still stuck. So please excuse if my question is trivial in your eyes.

I am trying to write down the grad of a scalar field in a relatively generic way, but getting the error

ValueError: no common basis for the contraction

At a higher level, my goal is to prove a few basic lemmas about the grad, both as an exercise to learn Manifolds and as part of a larger project.

The following code just sets up the preliminaries and defines the metric:

# preliminaries
from sage. All import *
from sage.manifolds.operators import *
M = Manifold(4, 'M', latex_name=r'\mathcal{M}', structure='Lorentzian')
X.<t,x,y,z> = M.chart()
U = M.open_subset('U', coord_def={X: (y!=0, x<0)})
X_U = X.restrict(U)
F = U.scalar_field(function('f')(t,x,y,z), chart=X_U, name='F')
F.display()

# definition of metric
g = M.metric('g',)
print(g)
g[0,0] = function('g00')(t,x,y,z)
g[1,0] = g[0,1] = function('g01')(t,x,y,z)
g[2,0] = g[0,2] = function('g02')(t,x,y,z)
g[3,0] = g[0,3] = function('g03')(t,x,y,z)
g[1,1] = function('g11')(t,x,y,z)
g[1,2] = g[2,1] = function('g12')(t,x,y,z)
g[1,3] = g[3,1] = function('g13')(t,x,y,z)
g[2,2] = function('g22')(t,x,y,z)
g[2,3] = g[3,2] = function('g23')(t,x,y,z)
g[3,3] = function('g33')(t,x,y,z)
g.display()

All of the above works (thank you). But now I try to do:

grad(F)

and I get the error above.

Obviously I am missing something basic.

Thank you GPN