1
$\begingroup$

I'm new to Mathematica and I'm stuck on this piece of code. The code is supposed to let the user choose how many inequalities (in a number between 1 and 5) they want to be evaluated.

Manipulate[Column[{Table[
With[{index = i}, InputField[Dynamic[var[index]], String, ContinuousAction -> True, FieldHint -> "Field " <> ToString[index]]], {i, n}]
}], {{n, 2}, 2, 5, 1}, Initialization :> (var[_] = "";)]

So far so good, the code seems to what we need: it varies automatically the number of InputFields. The next step I need is to automatically evaluate each single inequality quand print their solution as an output by using the Reduce function. How can I achieve it?

$\endgroup$

1 Answer 1

1
$\begingroup$

Something like:

Clear[var]
Manipulate[
 Column[{Table[
    With[{index = i}, 
     if[index] = 
      InputField[Dynamic[var[index]], String, 
       ContinuousAction -> True, 
       FieldHint -> "Field " <> ToString[index]]], {i, n}],
   Button["Evaluate", 
    Do[var[i] = 
      StringJoin[var[i], " = ", ToString[ToExpression[var[i]]]], {i, 
      n}]],
   Button["Clear", Do[var[i] = " ", {i, n}]]
   }]
 , {{n, 2}, 1, 5, 1}, Initialization :> Do[var[i] = " ", {i, n}]]

enter image description here

Then when you give some input and click "Evaluate":

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.