50

Example: I have a matrix $R = \left( \begin{array}{cc} A & \mathbf{t} \\ 0 & 1 \end{array} \right) $ where $A$ is 3-by-3 and $\mathbf{t}$ is 3 by 1. Or in Mathematica

 A={{1,0,0},{0,0,1},{0,-1,0}};
 t={1,1,1}

I would like to be able to use a form of block matrix notation / entry and subsequently find the inverse of R.

Question: Is this possible?

rcollyer
  • 33,976
  • 7
  • 92
  • 191
nilo de roock
  • 9,657
  • 3
  • 35
  • 77

2 Answers2

62

You're looking for ArrayFlatten. For your example matrices,

 R = ArrayFlatten[ {{A, {t}\[Transpose]},{0, 1}} ]
 (*
 => {{1, 0, 0, 1}, {0, 0, 1, 1}, {0, -1, 0, 1}, {0, 0, 0, 1}}
 *)

The construct {t}\[Transpose] is necessary for ArrayFlatten to treat t as a column matrix.

Mathematica graphics

Then to find $\boldsymbol{R}^{-1}$, you run

Inverse[R]
(* 
=> {{1, 0, 0, -1}, {0, 0, -1, 1}, {0, 1, 0, -1}, {0, 0, 0, 1}}
*)
rcollyer
  • 33,976
  • 7
  • 92
  • 191
  • 1
    beat me by 5s... – acl Jan 26 '12 at 16:25
  • He was also asking for the inverse - could add this for completeness. – Vitaliy Kaurov Jan 26 '12 at 16:31
  • @VitaliyKaurov, done! – rcollyer Jan 26 '12 at 16:36
  • @acl, it's a testament to how much we've been waiting for these types of questions when 3 of the top users jump on it within seconds of each other. – rcollyer Jan 26 '12 at 16:38
  • This point about {t}\[Transpose] being necessary is important and subtle: Mathematica (to its credit) does NOT finesse the fact that vectors must be either 1 x n or n x 1 matrices, that is, explicitly either row or column vectors. Pretty much everything else (including my beloved Golub & VanLoan) does (tho G&VL have the grace at least to say they do). I find the conceptual hygiene forced by Mathematica to be refreshing and helpful. – Reb.Cabin Jul 27 '14 at 17:32
  • Fair warning to others, this didn't work for me. All my blocks were vectors of the same size (in a sparse array). ArrayFlatten did give me a consistently dimensioned array, but it put every element in its own list. (Where a should have been, it put {a}.) The other solution, where I could use Ctrl+Enter and Ctrl+, worked though. – Travis Bemrose Dec 05 '15 at 01:59
30

The keyboard commands Ctrl+Enter, Ctrl+, and Tab can be used to enter this format.

You can also use the menu Insert > Table/Matrix to create a table of specified size with placeholders.

See Entering Tables and Matrices.


Depending on the meaning of the question, this may have some bearing:

Mathematica graphics

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • 2
    beat you to it. :P – rcollyer Jan 26 '12 at 16:23
  • 2
    LOL at the pity vote. – Mr.Wizard Jan 26 '12 at 16:27
  • I meant, I beat you to posting the "correct" answer. Although, I posted the result he wanted, and you posted the entry method. Win for both of us. – rcollyer Jan 26 '12 at 16:28
  • Not a pity vote. If you don't post this, I would have edited it into @rcollyer's answer. It's much more convenient to enter matrices like this (see my screenshot). – Szabolcs Jan 26 '12 at 16:29
  • @Szabolcs, I have mixed feelings of entering matrices that way. For a simple matrix, like the OP's, then I prefer just typing it out. If it's much larger, then this route is better, especially getting structure correct. – rcollyer Jan 26 '12 at 16:32
  • 8
    @rcollyer Recently I saw someone give input to NDSolve that way, and I really liked it --> http://i.stack.imgur.com/bgWJ3.png – Szabolcs Jan 26 '12 at 16:47
  • @Szabolcs, it definitely has its merits. – rcollyer Jan 26 '12 at 16:58