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

(*ex: List1[[1]]={{1,2},{3,4}} *)

Suppose that we have the following code with 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.

    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?

  • $\begingroup$ Please provide code that actually demonstrates your question/issue. The answerers shouldn't have to guess what you mean and make their own additions.... $\endgroup$ – ktm Oct 3 '18 at 23:34
  • $\begingroup$ @user6014: I will edit the question now. Thanks. $\endgroup$ – Tugrul Temel Oct 3 '18 at 23:35
  • $\begingroup$ @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? $\endgroup$ – 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:

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]}]

enter image description here

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]}]
  • $\begingroup$ Your proposal is a very elegant and structural solution to my question. I need to work on your proposal to digest it. $\endgroup$ – 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};

 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};

 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.

  • $\begingroup$ 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. $\endgroup$ – Tugrul Temel Oct 4 '18 at 0:03
  • $\begingroup$ Your first manipulate only gives one plot at a time, so why would this give more than one determinant at a time? $\endgroup$ – ktm Oct 4 '18 at 0:06
  • $\begingroup$ 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. $\endgroup$ – Tugrul Temel Oct 4 '18 at 11:04

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.