How can I define a metric in xAct?

I'm using "xAct" package and I want to define a my metric, that is a non standard metric. For example, my metric is diagonal

 g={-e^(2a),e^(2b),e^(2b),e^(2b),e^(2c),e^(2c)sin^2(theta)},


where a,b,c are functions of the time variable t. I cannot understand how I can insert this definition when I use the command DefMetric...Can anyone help me?

• have you looked at mathematica.stackexchange.com/questions/67446/… (see search button top right) Dec 20, 2014 at 9:16
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– user9660
Dec 20, 2014 at 9:24
• Yes, I've looked, but the problem is that I have a manifold in 6D and at a certain point Mathematica finds errors, even if I execute standard metric! Is there (or Do you know) a more simple package than xAct that calculates Riemann and Ricci tensors and the Gauss Bonnet term? Dec 20, 2014 at 9:56

First of all, note that you'll need to use xCoba to do any calculations in terms of coordinate components. From the xTensor documentation page:

xTensor does not perform component calculations. Use the companion package xCoba.

In xCoba, you need to define a "chart" on your manifold with the coordinates you're using, and explicitly call DefScalarFunction for the functions you're going to be using. For example, here's how you'd define a flat FRW metric:

<< xActxCoba
(* Define the manifold *)
DefManifold[M, 4, IndexRange[a, n]]

(* Define coordinates on a chart of M *)
DefChart[ch, M, {0, 1, 2, 3}, {t[], x[], y[], z[]}, ChartColor -> Blue]

(* Define aa (the scale factor) to be a scalar function of one or more coordinates *)
DefScalarFunction[aa]

(* Create the metric tensor in terms of its coordinate components *)
met = CTensor[DiagonalMatrix[{-1, aa[t[]]^2, aa[t[]]^2, aa[t[]]^2}], {-ch, -ch}];

(* Set this metric to be the metric of the manifold on the chart ch *)
SetCMetric[met, ch, SignatureOfMetric -> {3, 1, 0}]

(* Define the covariant derivative operator *)
cd = CovDOfMetric[met];

(* Calculate various curvature tensors and cache *)
MetricCompute[met, ch, All]

(* Display Kretschmann invariant *)
Kretschmann[cd][]

Out[] = (12 (aa'[t[]]^4 + aa[t[]]^2 (aa'')[t[]]^2))/aa[t[]]^4


The Gauss-Bonnet invariant is not automatically computed by MetricCompute, but you could easily define it in terms of the appropriate contractions.

Note that none of this is terribly clear in the main xCobaDoc.nb file that's linked to on the main xCoba page. However, when you download and install the package, there should be a file called xCobaDoc2.nb in the Documentation directory that gives a lot more detail on how to use CTensor to define coordinate tensors, with some helpful examples. That's how I personally figured out how to use the package...

• what is the {-ch,-ch} for in the met=CTensor[...] part?
– jboy
Jul 7, 2021 at 11:48
• @jboy: It signifies that you're giving the metric components in terms of the ch coordinates. The - signs signify that you're providing the components of $g_{\mu \nu}$ in this basis; if you wanted to provide $g^{\mu \nu}$, you would use {ch, ch} instead. Jul 7, 2021 at 11:58
• thanks for that. How about this line SetCMetric[met, ch, SignatureOfMetric -> {3, 1, 0}] what does {3,1,0} mean? isnt the signature for the robertson-walker metric -1,1,1,1?
– jboy
Jul 7, 2021 at 14:07
• @jboy: The order of elements in that list is "numbers of +s", "number of -s", "number of 0s". Jul 7, 2021 at 14:48

MetricInBasis[metric,-B,yourmetric] can work. See "Spherical Symmetry" of xCoba examples for more information.