2
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ MatrixForm[MapAt[MatrixForm, #, {2 ;;}] & /@ pp]? $\endgroup$ – kglr Jun 27 '14 at 4:36
  • $\begingroup$ Thank you so much, It was wonderful. I am so sorry can I ask a question,is the role of {2;;} for existence of 2 rows? for example if I had pp 3 rows I must write {3;;}? $\endgroup$ – Unbelievable Jun 27 '14 at 4:46
  • $\begingroup$ I posted a cleaner version using MapAt which should work regardless of the numbers of rows/columns. $\endgroup$ – kglr Jun 27 '14 at 4:52
  • $\begingroup$ Yes I saw, thank you so much $\endgroup$ – Unbelievable Jun 27 '14 at 4:54
3
$\begingroup$
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

|improve this answer|||||
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Unbelievable Jun 27 '14 at 5:14
  • $\begingroup$ @mostafa, I find the tutorials in Virtual Book extremely useful. $\endgroup$ – kglr Jun 27 '14 at 5:51
3
$\begingroup$

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}]]&
|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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