Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
+1 vote

I don't know how to manipulate matrix easily in Cadabra. For example, some Lagrangian like

$$ L=Tr(\partial_{\mu}{A}\partial^{\mu}{A}), $$

where $A=diag(a, b)$, the right result is

$$ L=\partial_{\mu}{a}\partial^{\mu}{a}+\partial_{\mu}{b}\partial^{\mu}{b}. $$

How to implement the above steps in Cadabra? I have a try

{\mu,\nu}::Indices(vector).
{c,d,e,f}::Indices(values={1,2}).
\partial{#}::Derivative.
g_{c d}::Metric.
g^{c d}::InverseMetric.
metric:={g_{1 1}=1,g_{2 2}=1};
complete(_,$g^{c d}$);
A:={A_{1 1}=a,A_{2 2}=b};
{a,b}::Depends(\partial{#}).
L:=g^{c d}(\partial_{\mu}{A}\partial^{\mu}{A})_{c d};
expand(_);
evaluate(_,metric+A);

but it doesn't work.

in General questions by (2.1k points)
edited by

Please log in or register to answer this question.

...