Message Boards Message Boards

0
|
5002 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Building block matrices so trace works properly

Posted 12 years ago
Hi,
My question is the following.
suppose I have  block matrices:
A={{a,0},{0,0}};
B={{b,0},{0,0}};
C={{c,0},{0,0}};
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,
Diego
POSTED BY: diego pasquier
4 Replies
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
Posted 12 years ago
Thank you for your help!
POSTED BY: diego pasquier
Posted 12 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
Tr[mata.matb.matc]
Tr[matb.mata.matc]

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
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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract