1

I want user to input a matrix. I have the below code for this.

rmatrix = {{Input["r11"], Input["r12"]}, {Input["r21"], Input["r22"]}}

But it shows a separate dialog for each item. I want to get the complete matrix in one dialog.

I also tried it in another way. check the code below.

form = FormFunction[{{"r11" -> "Number", 
     "r12" -> "Number"}, {"r21" -> "Number", "r22" -> "Number"}}, 
   MatrixForm];

But I don't know how to assign these values to matrix.

sheldon cooper
  • 455
  • 2
  • 8
  • 22

2 Answers2

2
Interpretation[{
  r11 = MakeBoxes[0],
  r12 = MakeBoxes[0],
  r21 = MakeBoxes[0],
  r22 = MakeBoxes[0]}, Panel[Grid[{
    {InputField[Dynamic[r11], Boxes, FieldSize -> Tiny], 
     InputField[Dynamic[r12], Boxes, FieldSize -> Tiny]},
    {InputField[Dynamic[r21], Boxes, FieldSize -> Tiny], 
     InputField[Dynamic[r22], Boxes, FieldSize -> Tiny]}
    }]],
 With[{r11 = ToExpression[r11], r12 = ToExpression[r12], 
   r21 = ToExpression[r21], 
   r22 = ToExpression[r22]}, {{r11, r12}, {r21, r22}}]]

img

Daniel
  • 7,684
  • 7
  • 52
  • 76
1
rmatrix = DialogInput[{r11, r12, r21, r22}, Grid[{
     {"r11", InputField[Dynamic[r11], Number], "r12", 
      InputField[Dynamic[r12], Number]},
     {"r21", InputField[Dynamic[r21], Number], "r22", 
      InputField[Dynamic[r22], Number]},
     {
      Button["done", DialogReturn[{{r11, r12}, {r21, r22}}], 
       ImageSize -> Automatic]}}]];

enter image description here

If you do like this it won't let you exit without entering all the values:

rmatrix = DialogInput[{r11, r12, r21, r22}, Grid[{
     {"r11", InputField[Dynamic[r11], Number], "r12", 
      InputField[Dynamic[r12], Number]},
     {"r21", InputField[Dynamic[r21], Number], "r22", 
      InputField[Dynamic[r22], Number]},
     { Button["done", DialogReturn[{{r11, r12}, {r21, r22}}], 
       ImageSize -> Automatic, 
       Enabled -> Dynamic[AllTrue[{r11, r12, r21, r22}, NumericQ]]]}}]];
agentp
  • 6,849
  • 2
  • 19
  • 37