2

I have a nested matrix n:

n = {{a, b}, {c, d}}
a = {{0, t, q, dh}, {0, 1, 0, th}, {1, 1, 0, sh}}
b = {{0, t, q, dh}, {1, 0, 0, th}, {1, 0, 0, sh}}

c = {{0, t, q, dh}, {0, 1, 0, th}, {1, 0, 0, sh}}
d = {{0, t, q, dh}, {0, 0, 0, th}, {0, 1, 0, sh}}

With thanks to Nasser add column and Andy and Mike most efficient for their questions and answers, we can add a vector m = {rr, kk} to this nested matrix as a column, for example:

pp = Transpose[Insert[Transpose[n], Flatten@m, 1]]
or
pp=Join[List /@ m, n, 2] // MatrixForm

Finally, after running the above lines we have pp as:

{{rr, {{0, t, q, dh}, {0, 1, 0, th}, {1, 1, 0, sh}},       
      {{0, t, q, dh}, {1, 0, 0, th}, {1, 0, 0, sh}}}, 
 {kk, {{0, t, q, dh}, {0, 1,0, th}, {1, 0, 0, sh}}, 
      {{0, t, q, dh}, {0, 0, 0, th}, {0, 1, 0,sh}}}}

and pp/MatrixForm as: enter image description here

The result is correct but I wanted to obtain an obvious and clarified figure of pp/MatrixForm same as :

enter image description here

Are there any possibility for obtaining the last form instead of the first form for pp/MatrixForm.

Unbelievable
  • 4,847
  • 1
  • 20
  • 46

2 Answers2

3

Let's define your matrix as

p = {{rr, {{0, t, q, dh}, {0, 1, 0, th}, {1, 1, 0, sh}},       
  {{0, t, q, dh}, {1, 0, 0, th}, {1, 0, 0, sh}}}, 
  {kk, {{0, t, q, dh}, {0, 1,0, th}, {1, 0, 0, sh}}, 
  {{0, t, q, dh}, {0, 0, 0, th}, {0, 1, 0,sh}}}};

You could do the MatrixForm on the outermost and the inner levels:

#[Map[#,p,{2}]]&@MatrixForm

MATRIX

An alternative form would be

MatrixForm//#[Map[#,p,{2}]]&
Jens
  • 97,245
  • 7
  • 213
  • 499
3
pp = {{rr, {{0, t, q, dh}, {0, 1, 0, th}, {1, 1, 0, sh}},       
          {{0, t, q, dh}, {1, 0, 0, th}, {1, 0, 0, sh}}}, 
     {kk, {{0, t, q, dh}, {0, 1,0, th}, {1, 0, 0, sh}}, 
          {{0, t, q, dh}, {0, 0, 0, th}, {0, 1, 0,sh}}}}; 

MapAt[MatrixForm, pp, {{All, All}, {}}]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
  • Inasmuch as, I need so much to do work with matrices, are there any comprehensive documents for the matrices category and some related syntax, like Map, Mapat, MapThread and so on? because the help of Mathematica is not enough for being expert in this territory. – Unbelievable Jun 27 '14 at 05:14
  • @mostafa, I find the tutorials in Virtual Book extremely useful. – kglr Jun 27 '14 at 05:51