I'm working on a cosmological model for general relativity, and I need to define a tensor and assign values to this. For example, a tensor $A_{\mu\nu}$ that is a function of other tensors:

$$A_{\mu\nu}=R_{\mu\alpha}g^{\mu \alpha}+G^{\mu\beta}T_{\beta\nu}$$

And I need to use this expression for $A_{\mu\nu}$ to calculate the covariant derivative of this. I have the components of every tensor of this expression ($T_{00}=\cos(\theta), T_{11}=\sin(\theta)$, etc..), but I need express $A_{\mu\nu}$ in this way.

How can I do this in xAct? because in the tutorials of xCoba I didn't find something like this.


2 Answers 2


You can do the following (there might be more alternatives):

1 Define a tensor to represent A_{\mu\nu} (I assume that M4 is your manifold):

In[]:= DefTensor[A[-mu,-nu],M4]

2 Type your expression with the correct index configuration (there are indices misplaced in your original expression):

In[]:= expr = A[-mu,-nu]==R[-mu,-alpha]g[-nu,alpha]+G[-mu,beta]T[-beta,-nu]

3 Use xCoba commands to compute the components of A[-mu,-nu] (I assume that B is your basis):

In[]:= ToBasis[B]/@expr;

4 The last output should be a list giving all the components you are looking for in the base B if all the components of the tensors in the R.H.S have been already computed.

  • 1
    $\begingroup$ Thank you!, It works!! @Alfonso But I have another question. How do you define a specific tensor by assignation of every single component?? For example, I need to define $$u^\mu \longrightarrow(0,1,cos(\phi),\sin(\phi))$$ $\endgroup$ May 1, 2017 at 21:29

To define a specific tensor by the assignation of every single component

u = CTensor[{0, 1,cos[ϕ[]],sin[ϕ[]]}, {ch}]
  • 1
    $\begingroup$ Showing a specific example of the usage of your code would be helpful. $\endgroup$
    – bbgodfrey
    Aug 16, 2023 at 12:22

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.