How i can extract different sub matrix using index of sub matrix

Sir i am try to to make a general program that extract different sub matrix that have elements at different positions., here is may program that is well working .. but now i want to transform this program in a general one that take my index of matrix one by one and display a desired matrix here i extracted a one element D13,,,now i want to define input as d=[1,3,16], i want that program picks a index of yhe matrix yourself

 m1 = ConstantArray[0, {2, 2}];
For[i = 1; ii = 1, i <= 3, i += 2; ii += 1,
For[j = 1; jj = 1, j <= 3, j += 2; jj += 1,
m1[[ii, jj]] = \[CurlyCapitalUpsilon][[i, j]]]];
m1 // MatrixForm
m2 = ConstantArray[0, {2, 2}];
For[i = 1; ii = 1, i <= 3, i += 2; ii += 1,
For[j = 9; jj = 1, j <= 11, j += 2; jj += 1,
m2[[ii, jj]] = \[CurlyCapitalUpsilon][[i, j]]]];
m2 // MatrixForm
m3 = ConstantArray[0, {2, 2}];
For[i = 9; ii = 1, i <= 11, i += 2; ii += 1,
For[j = 1; jj = 1, j <= 3, j += 2; jj += 1,
m3[[ii, jj]] = \[CurlyCapitalUpsilon][[i, j]]]];
m3 // MatrixForm
m4 = ConstantArray[0, {2, 2}];
For[i = 9; ii = 1, i <= 11, i += 2; ii += 1,
For[j = 9; jj = 1, j <= 11, j += 2; jj += 1,
m4[[ii, jj]] = \[CurlyCapitalUpsilon][[i, j]]]];
m4 // MatrixForm
ArrayFlatten[{{m1, m2}, {m3, m4}}] // MatrixForm
{{1 + 2 \[Mu], 0, 0, 0}, {0, 1 + 2 \[Mu], 0, 0}, {0, 0, 1 + 2 \[Mu],
0}, {0, 0, 0, 1 + 2 \[Mu]}}

• The question seems incomplete. What is D13 ? And also we cannot evaluate your code without knowing what [CurlyCapitalUpsilon] is. Finally what exactly do you want as the result ? Please make it clear. Jul 18 '18 at 8:58
• [CurlyCapitalUpsilon mean curly brackets here D13 is a sub matrix that have index 13... actually i want to make a program that extract sub matrix by just give index Jul 18 '18 at 9:26

Your code produces the same output as the following simpler code:

ϒ[[{1, 3, 9, 11}, {1, 3, 9, 11}]]


Update: my understanding of

... 13 is a one 4*4 matrix just as above in my program, 14 is also a 4*4 matrix and 16 an15 is also a 4*4 matrix

is that we are given an indexed set of 4X4 submatrices, and we want to use the submatrix index to extract elements from the main matrix ϒ.

We make a list of rules associating a submatrix index to the rows and column indices in the main matrix:

submatrixindices = Range[14];
rowcolumnindices = RandomChoice[Range[15], {14, 2, 4}];


and define a function extractSubmat[m, sm, rules] that, for given submatrix index sm and rules mapping submatrix indices to row and column indices for m, returns the corresponding elements from matrix m

extractSubmat[m_, sm_, rules_] := m[[## & @@ (sm /. rules)]];


Example:

ϒ = Array[a, {15, 15}];
ϒ // MatrixForm // TeXForm


$\tiny \left( \begin{array}{ccccccccccccccc} a_{1,1} & a_{1,2} & a_{1,3} & a_{1,4} & a_{1,5} & a_{1,6} & a_{1,7} & a_{1,8} & a_{1,9} & a_{1,10} & a_{1,11} & a_{1,12} & a_{1,13} & a_{1,14} & a_{1,15} \\ a_{2,1} & a_{2,2} & a_{2,3} & a_{2,4} & a_{2,5} & a_{2,6} & a_{2,7} & a_{2,8} & a_{2,9} & a_{2,10} & a_{2,11} & a_{2,12} & a_{2,13} & a_{2,14} & a_{2,15} \\ a_{3,1} & a_{3,2} & a_{3,3} & a_{3,4} & a_{3,5} & a_{3,6} & a_{3,7} & a_{3,8} & a_{3,9} & a_{3,10} & a_{3,11} & a_{3,12} & a_{3,13} & a_{3,14} & a_{3,15} \\ a_{4,1} & a_{4,2} & a_{4,3} & a_{4,4} & a_{4,5} & a_{4,6} & a_{4,7} & a_{4,8} & a_{4,9} & a_{4,10} & a_{4,11} & a_{4,12} & a_{4,13} & a_{4,14} & a_{4,15} \\ a_{5,1} & a_{5,2} & a_{5,3} & a_{5,4} & a_{5,5} & a_{5,6} & a_{5,7} & a_{5,8} & a_{5,9} & a_{5,10} & a_{5,11} & a_{5,12} & a_{5,13} & a_{5,14} & a_{5,15} \\ a_{6,1} & a_{6,2} & a_{6,3} & a_{6,4} & a_{6,5} & a_{6,6} & a_{6,7} & a_{6,8} & a_{6,9} & a_{6,10} & a_{6,11} & a_{6,12} & a_{6,13} & a_{6,14} & a_{6,15} \\ a_{7,1} & a_{7,2} & a_{7,3} & a_{7,4} & a_{7,5} & a_{7,6} & a_{7,7} & a_{7,8} & a_{7,9} & a_{7,10} & a_{7,11} & a_{7,12} & a_{7,13} & a_{7,14} & a_{7,15} \\ a_{8,1} & a_{8,2} & a_{8,3} & a_{8,4} & a_{8,5} & a_{8,6} & a_{8,7} & a_{8,8} & a_{8,9} & a_{8,10} & a_{8,11} & a_{8,12} & a_{8,13} & a_{8,14} & a_{8,15} \\ a_{9,1} & a_{9,2} & a_{9,3} & a_{9,4} & a_{9,5} & a_{9,6} & a_{9,7} & a_{9,8} & a_{9,9} & a_{9,10} & a_{9,11} & a_{9,12} & a_{9,13} & a_{9,14} & a_{9,15} \\ a_{10,1} & a_{10,2} & a_{10,3} & a_{10,4} & a_{10,5} & a_{10,6} & a_{10,7} & a_{10,8} & a_{10,9} & a_{10,10} & a_{10,11} & a_{10,12} & a_{10,13} & a_{10,14} & a_{10,15} \\ a_{11,1} & a_{11,2} & a_{11,3} & a_{11,4} & a_{11,5} & a_{11,6} & a_{11,7} & a_{11,8} & a_{11,9} & a_{11,10} & a_{11,11} & a_{11,12} & a_{11,13} & a_{11,14} & a_{11,15} \\ a_{12,1} & a_{12,2} & a_{12,3} & a_{12,4} & a_{12,5} & a_{12,6} & a_{12,7} & a_{12,8} & a_{12,9} & a_{12,10} & a_{12,11} & a_{12,12} & a_{12,13} & a_{12,14} & a_{12,15} \\ a_{13,1} & a_{13,2} & a_{13,3} & a_{13,4} & a_{13,5} & a_{13,6} & a_{13,7} & a_{13,8} & a_{13,9} & a_{13,10} & a_{13,11} & a_{13,12} & a_{13,13} & a_{13,14} & a_{13,15} \\ a_{14,1} & a_{14,2} & a_{14,3} & a_{14,4} & a_{14,5} & a_{14,6} & a_{14,7} & a_{14,8} & a_{14,9} & a_{14,10} & a_{14,11} & a_{14,12} & a_{14,13} & a_{14,14} & a_{14,15} \\ a_{15,1} & a_{15,2} & a_{15,3} & a_{15,4} & a_{15,5} & a_{15,6} & a_{15,7} & a_{15,8} & a_{15,9} & a_{15,10} & a_{15,11} & a_{15,12} & a_{15,13} & a_{15,14} & a_{15,15} \\ \end{array} \right)$

Column[{Row[{"submatrix : ", #}],
Row[{"row column indices : ", # /. submatindextorowscolsrule}] ,
MatrixForm@extractSubmat[ϒ, #, submatindextorowscolsrule]}] & /@ {10, 13, 6, 9} // Column[#, Frame -> All] &


• Right but i want to make a general program that evaluate many matrix just by addind index 13 ,14,16,15, Jul 18 '18 at 9:22
• @muhammadasif, does ϒ[[#, #]] & @{13,14,16,15} give what you want?
– kglr
Jul 18 '18 at 9:27
• this is working but this giving me a 4*4 matrix but 13 is a one 4*4 matrix just as above in my program, 14 is also a 4*4 matrix and 16 an15 is also a 4*4 matrix each ,,, if i write index 1 its mean a 2*2 matrix Jul 18 '18 at 9:50
• @muhammedasif, please see the update.
– kglr
Jul 18 '18 at 11:46
• actually i want to evaluate e equation that will picks each submatrix and add with identity matrix and calculate the determinent .such as(-2 (1 - v))^1/Sqrt[Det[D1 + A]]+((-2 (1 - v))^2/Sqrt[Det[D13 + B]]) ,.... i have such 246 terms with different sub matrix ,,, i dont knw how i do it any idea pllz Jul 20 '18 at 8:14