# Slider for a list of real numbers versus a list of matrices

Suppose that there are two lists, where capital letters in List1 denote matrices.

List1={A1,A2,A3,A4,A5}
={{{1,2},{3,4}},{{0,1},{3,1}},{{1,1},{2,3}},{{2,1},{5,0}},{{1,1},{2,2}}};
(*ex: List1[[1]]={{1,2},{3,4}} *)
List2={1,2,3,4,5};


Suppose that we have the following code with Manipulate:

Manipulate[
Plot[Sin[b1 x], {x, 0, 10}],
Row[{Control[{b1, List2, Animator, AnimationRunning -> False}]}]
];


This nicely works. However, applying the same logic to the following code with a list of matrices, List1, does not work.

  Manipulate[
Det[B1*B1],
Row[{Control[{B1, List1, Animator, AnimationRunning -> False}]}]
];


I do not want to use Matrix index such as List1[[k]] to retrieve k-th sub-matrix because in a large code matrix indices are a bit difficult to use. I just want to apply the same logic that is valid for List2.

Is there anyway to run the second Manipulate above for matrices without specifying matrix index?

• Please provide code that actually demonstrates your question/issue. The answerers shouldn't have to guess what you mean and make their own additions.... – user6014 Oct 3 '18 at 23:34
• @user6014: I will edit the question now. Thanks. – Tugrul Temel Oct 3 '18 at 23:35
• @user6014: The question is edited to give a specific list of matrices to run the 2nd Manipulate. When you run it, only the first sub-matrix $List1[[1]]$ is used to generate Det=-20. But the other sub-matrices are not used to calculate the Det. My question is Why? – Tugrul Temel Oct 3 '18 at 23:46

List1 = {A1, A2, A3, A4, A5} = Array[Symbol["a" <> ToString[#]][##2] &, {5, 2, 2}];


Cheating via the second argument of Dynamic:

ClearAll[animator]
animator[lst_] := Animator[Dynamic[#, {(b = #; B1 = lst[[#]]) &}], {1, Length@lst, 1},
AnimationRunning -> False] &;

Manipulate[Det[B1 B1], {{b, First@List1, "B1"}, List1, animator[List1]},
Initialization -> {B1 = First[List1]}]


Note: The first two arguments of control, as long as the control is named b, does not matter. That is, the following gives the same result:

Manipulate[Det[B1 B1], {{b, blah, "B1"}, blahblah, animator[List1]},
Initialization -> {B1 = First[List1]}]

• Your proposal is a very elegant and structural solution to my question. I need to work on your proposal to digest it. – Tugrul Temel Oct 4 '18 at 11:25

This is an issue that comes into effect when List1 contains 2x2 matrices. The Control option takes a length 2 list as a 2nd argument, so it's confusing your matrices with that syntax. Note that this does not happen with 3x3 matrices:

A1 := RandomReal[10, {3, 3}]
A2 := RandomReal[10, {3, 3}]
A3 := RandomReal[10, {3, 3}]
A4 := RandomReal[10, {3, 3}]
A5 := RandomReal[10, {3, 3}]

List2 = {A1, A2, A3, A4, A5};

Manipulate[Det[B1*B1],
Row[{Control[{B1, List2, Animator, AnimationRunning -> False}]}]]


In my opinion, the easiest way to avoid this is to just use the Part operator if you're dealing with a list of 2x2 matrices:

A1 := RandomReal[10, {2, 2}]
A2 := RandomReal[10, {2, 2}]
A3 := RandomReal[10, {2, 2}]
A4 := RandomReal[10, {2, 2}]
A5 := RandomReal[10, {2, 2}]

List2 = {A1, A2, A3, A4, A5};

Manipulate[Det[List2[[B1]]^2],
Row[{Control[{B1, Range[5], Animator, AnimationRunning -> False}]}]]


No doubt there exist other ways, but that's what I do. Sorry , I know you said it was what you wanted to avoid.

• I checked your response but unfortunately your examples do not work either. What you get is only a single number and other four Det are not calculated. The answer expected should be a list of 5 determinants. That is what I expect. – Tugrul Temel Oct 4 '18 at 0:03
• Your first manipulate only gives one plot at a time, so why would this give more than one determinant at a time? – user6014 Oct 4 '18 at 0:06
• I have five matrices and want to calculate five Det's. I want to get one Det at a time, but I cannot. Maybe, kglr's proposal below will clarify the question because his answer solves my problem. Thanks for your efforts. – Tugrul Temel Oct 4 '18 at 11:04