50
$\begingroup$

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?

$\endgroup$
0

2 Answers 2

62
$\begingroup$

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}}
*)
$\endgroup$
6
  • 1
    $\begingroup$ beat me by 5s... $\endgroup$
    – acl
    Jan 26, 2012 at 16:25
  • $\begingroup$ He was also asking for the inverse - could add this for completeness. $\endgroup$ Jan 26, 2012 at 16:31
  • $\begingroup$ @VitaliyKaurov, done! $\endgroup$
    – rcollyer
    Jan 26, 2012 at 16:36
  • $\begingroup$ @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. $\endgroup$
    – rcollyer
    Jan 26, 2012 at 16:38
  • $\begingroup$ 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. $\endgroup$
    – Reb.Cabin
    Jul 27, 2014 at 17:32
29
$\begingroup$

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

$\endgroup$
7
  • 2
    $\begingroup$ beat you to it. :P $\endgroup$
    – rcollyer
    Jan 26, 2012 at 16:23
  • 2
    $\begingroup$ LOL at the pity vote. $\endgroup$
    – Mr.Wizard
    Jan 26, 2012 at 16:27
  • $\begingroup$ 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. $\endgroup$
    – rcollyer
    Jan 26, 2012 at 16:28
  • $\begingroup$ 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). $\endgroup$
    – Szabolcs
    Jan 26, 2012 at 16:29
  • 8
    $\begingroup$ @rcollyer Recently I saw someone give input to NDSolve that way, and I really liked it --> i.stack.imgur.com/bgWJ3.png $\endgroup$
    – Szabolcs
    Jan 26, 2012 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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