Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am fairly new to Mathematica but I thought I would be a helpful tool to carry out a few simple linear algebra calculations. It seems like an easy task but I cannot figure out how to do it. For example, say I want to multiply two matrices composed of sub-matrices:

P := {{P1, P12}, {P12\[Transpose], P2}}; Q := {{Q1, Q12}, {Q12\[Transpose], Q2}};
P.Q

but it returns:

{{P1 Q1 + P12 Transpose[Q12], P1 Q12 + P12 Q2}, 
 {Q1 Transpose[P12] + P2 Transpose[Q12], P2 Q2 + Q12 Transpose[P12]}}

How can I get a non-commutative result (e.g. the bottom left element should be P12\[Transpose] Q1)? Also, how do I get it to show the little transpose 'T' instead of writing it out?

I found similar questions posted:

Can Mathematica do symbolic linear algebra?

http://stackoverflow.com/questions/5708208/symbolic-matrices-in-mathematica-with-unknown-dimensions

but I'm not trying to do anything as complicated as those.

share|improve this question
    
    
Transpose 'T': Just type esc-tr-esc after the matrix and it's done. –  Sjoerd C. de Vries Apr 26 '12 at 21:42
add comment

2 Answers

up vote 9 down vote accepted

Searke hints at the answer. Remembering that the dot product is a specific form of Inner:

Inner[Times,P,Q,Plus]

We can simply replace Times wtih NonCommutativeMultiply

Inner[NonCommutativeMultiply, P, Q, Plus]

With the output:

{
 {P1 ** Q1 + P12 ** Transpose[Q12],P1 ** Q12 + P12 ** Q2}, 
 {P2 ** Transpose[Q12] + Transpose[P12] ** Q1, P2 ** Q2 + Transpose[P12] ** Q12}
}
share|improve this answer
add comment

If you want to get into this topic there is an NonCommutativeMultiply (**)

and a tutorial on Flat and Orderless Functions.

share|improve this answer
    
Good point: Attributes[Times] gives {Flat, Listable, NumericFunction, OneIdentity, Orderless, Protected} –  tkott Apr 26 '12 at 14:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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