2
$\begingroup$

I am trying to make a demonstration that can take in a matrix and create a vector field. Currently I have the demonstration all functioning but to define the matrix it uses sliders. I know they cannot be used to to define strings within manipulate but numbers can. if possible it would be nice to be able to put the inputfields in a 2x2 grid. currently I have:

Manipulate[value[a, b, c, d, e, f, g, h, i],
 Style["Matrix values", 12, Bold],
 {a, -10, 10, 1},
 {b, -10, 10, 1},
 {c, -10, 10, 1},
 {d, -10, 10, 1},
 {{e, -10, "x-min"}, -20, 0, 1},
 {{f, 10, "x-max"}, 0, 20, 1},
 {{g, -10, "y-min"}, -20, 0, 1},
 {{h, 10, "y-max"}, 0, 20, 1},
 {{i, 5, "Solutions"}, 0, 50, 1}]

I would like a,b,c,d to be input boxes so I can put in a 2x2 matrix. If anyone could help that would be great. I think it would use InputField Function and the Dynamic function. THANKS!!!


Ok, so I have figured one big thing out. instead of:

{a,-10,10,1}

(this defines a slider of range -10 to 10 with a step of 1) replace the numbers with InputField

{a,InputField}

and then you can replace a with different names and a value seen on my e-i variables I still can't find out how to make it look like a 2x2 matrix.

a b

c d

instead of a

b

c

d

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – bbgodfrey Mar 11 '15 at 16:43
1
$\begingroup$

coaxing Manipulate to do what you want seems to be a bit of a black art. Perhaps there is cleaner way but this seems to work..

 Clear[a,b,c,d];
 Manipulate[
      m=Map[#[[1]] &, First@(List @@ matrix), {2}];
      MatrixForm@m,
        {matrix, 
          Grid[Map[InputField[Dynamic@#, FieldSize -> 5] &,
               {{a, b}, {c, d}}, {2}]]}] 

enter image description here

$\endgroup$
  • $\begingroup$ I have a possible simpler problem: I just want to enter a string as a control variable in a manipulate. But I cannot get it to work. Here is my last attempt: Clear[string]; Manipulate[string, {string, "a", InputField[Dynamic[string], String]}] $\endgroup$ – abwatson Apr 12 '17 at 23:40
1
$\begingroup$

The principal question seems to be how to format matrix input in matrix form. The rest is not explained clearly enough for me to address and seems extraneous.

The OP's approach:

Manipulate[value[a, b, c, d, e, f, g, h, i], 
 Style["Matrix values", 12, Bold],
 Grid[{
   {Control@{{a, 0}, InputField, ImageSize -> Small},
    Control@{{b, 0}, InputField, ImageSize -> Small}},
   {Control@{{c, 0}, InputField, ImageSize -> Small},
    Control@{{d, 0}, InputField, ImageSize -> Small}}
   }],
 {{e, -10, "x-min"}, -20, 0, 1}, {{f, 10, "x-max"}, 0, 20, 1},
 {{g, -10, "y-min"}, -20, 0, 1}, {{h, 10, "y-max"}, 0, 20, 1},
 {{i, 5, "Solutions"}, 0, 50, 1}]

Mathematica graphics

Entering a matrix as a matrix: Here, instead of each component of the matrix being its own symbol & variable, I used a single matrix. Working with this form seems less cumbersome to me, even though it takes a little extra code to get the input to work. (Irrelevant variables omitted.)

Manipulate[
 matrix,
 Style["Matrix values", 12, Bold],
 {{matrix, {{0, 0}, {0, 0}}},
  Grid[
    Table[With[{i = i, j = j},
      InputField[Dynamic[matrix[[i, j]]], ImageSize -> Tiny]],
     {i, 2}, {j, 2}]
    ] &}
 ]

Mathematica graphics

The use of With is explained in "A Good Trick to Know", in the tutorial Introduction to Dynamic (tutorial/IntroductionToDynamic#2125133640). It injects the value of the symbols into the Dynamic; without it, one would just have the symbol itself.

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