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 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.

share|improve this question
1  
MatrixForm[MapAt[MatrixForm, #, {2 ;;}] & /@ pp]? –  kguler Jun 27 at 4:36
    
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;;}? –  mostafa Jun 27 at 4:46
    
I posted a cleaner version using MapAt which should work regardless of the numbers of rows/columns. –  kguler Jun 27 at 4:52
    
Yes I saw, thank you so much –  mostafa Jun 27 at 4:54

2 Answers 2

up vote 3 down vote accepted
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

share|improve this answer
    
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. –  mostafa Jun 27 at 5:14
    
@mostafa, I find the tutorials in Virtual Book extremely useful. –  kguler Jun 27 at 5:51

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}]]&
share|improve this answer

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.