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


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?

  • $\begingroup$ have you looked at mathematica.stackexchange.com/questions/67446/… (see search button top right) $\endgroup$
    – chris
    Dec 20, 2014 at 9:16
  • $\begingroup$ 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! $\endgroup$
    – user9660
    Dec 20, 2014 at 9:24
  • $\begingroup$ 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? $\endgroup$
    – user23299
    Dec 20, 2014 at 9:56

2 Answers 2


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:

<< xAct`xCoba`
(* 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 *)

(* 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 *)

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...

  • $\begingroup$ what is the {-ch,-ch} for in the met=CTensor[...] part? $\endgroup$
    – jboy
    Jul 7, 2021 at 11:48
  • $\begingroup$ @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. $\endgroup$ Jul 7, 2021 at 11:58
  • $\begingroup$ 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? $\endgroup$
    – jboy
    Jul 7, 2021 at 14:07
  • $\begingroup$ @jboy: The order of elements in that list is "numbers of +s", "number of -s", "number of 0s". $\endgroup$ Jul 7, 2021 at 14:48

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.