Group Abstract Group Abstract

Message Boards Message Boards

Building block matrices so trace works properly

My question is the following.
suppose I have  block matrices:
Is there a way to tell Mathematica that a,b and c are some square matrices (say 3 by 3) so that the output of Tr[A.B.C] is something like Tr[a.b.c] instead of just abc?

Thanks in advance,
POSTED BY: diego pasquier
2 years ago
Hi Diego,

What do you mean with Tr. The trace of the transpose? Furthermore the variable 'C' is protected in Mathematica, it has a very special purpous. Always try to use small letters. What do you mean with the ',' do you mean dot-product? Please clarify what you want. The trace (the sum of the diagonal row) can be obtained by using Total[Diagonal].
POSTED BY: Sander Huisman
2 years ago
Hi Sander,

Sorry I wasn't very careful in writing my question. so let me rephrase it. Yes by "Tr" I mean the trace and by "." the dot product. If I write:
mata = {{a, 0}, {0, 0}};
matb = {{b, 0}, {0, 0}};
matc = {{c, 0}, {0, 0}};

And then

The output is
a b c
a b c
which is fine if a,b and c are numbers. However, if they are matrices, then in general Tr[a.b.c] and Tr[b.a.c] are different. So I would like to keep track of this, without having to define a, b and c.
POSTED BY: diego pasquier
2 years ago
ArrayFlatten will do the job.
a = RandomInteger[5, {3, 3}];
b = RandomInteger[5, {3, 3}];
f = RandomInteger[5, {3, 3}];

MatrixForm /@ {a, b, f}

A = {{a, 0}, {0, 0}};
B = {{b, 0}, {0, 0}};
F = {{f, 0}, {0, 0}};

MatrixForm[ArrayFlatten[#]] & /@ {A, B, F}

Now check:
In[]:= a.b.f // Tr
Out[]= 809

In[]:= ArrayFlatten[A].ArrayFlatten[B].ArrayFlatten[F] // Tr
Out[]= 809

Also see: How to enter matrices in block matrix format?
POSTED BY: Vitaliy Kaurov
2 years ago
Thank you for your help!
POSTED BY: diego pasquier
2 years ago