3
$\begingroup$

I want to make an equation where the values adjust to my slider which I inserted with manipulate.

Well, I tried, but when I use the slider the equation starts to fall apart. quadratic equation in mathematica

Actually this should happen

quadratic equation steps

Is it possible to make an quadratic equation in mathematica where the variables and their results adjust themselves to a slider which has been inserted with manipulate?

$\endgroup$
5
$\begingroup$

You could use Row and ToString:

Manipulate[
  Row[{"f(", a, ") = ", a^2, " = ", ToString[a]^2}],
  {a, 0, 10, 1}
]

Mathematica graphics

The problem is that you are effectively multiplying some strings and some other expressions together. Mathematica tries to order expressions in a canonical order. You could try wrapping a list of the elements in Row or you could convert the non-String items to strings using ToString and then use StringJoin (shorthand <>) to put them together.


Another approach, probably better:

Manipulate[
 TraditionalForm[ f[a] == a^2 == Superscript[a, 2] ],
 {a, 1, 10, 1}
]

Mathematica graphics

Note that since f is a symbol here and not a string, it is evaluated and if it has a value, e.g. f=3 than this leads to something like $3(1)=1=1^2$. You can prevent this by using "f"[a] instead, or to retain the () brackets and italic formatting of TraditionalForm you could use a baroque construct like this:

f[_] = "Fail!"; (* troublesome example definition *)

Manipulate[
 With[{a = a},
  TraditionalForm[HoldForm[f[a]] == a^2 == Superscript[a, 2]]
 ],
 {a, 1, 10, 1}
]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Hope you don’t mind the edit. I realise my draft wasn't different enough $\endgroup$ – Verbeia Sep 26 '12 at 11:32
  • $\begingroup$ @Verbeia much appreciated; my answer was incomplete but I'm getting sleepy. Time to quit I think. $\endgroup$ – Mr.Wizard Sep 26 '12 at 11:33
  • $\begingroup$ @Mr.Wizard How come Manipulate[ StringJoin["f(", a, ") = ", a^2, " = ", ToString[a]^2], {a, 1, 10, 1}] does not work ? $\endgroup$ – b.gates.you.know.what Sep 26 '12 at 11:34
  • $\begingroup$ @b.gatessucks you would need to convert a, a^2, and ToString[a]^2 to strings as well. That's why I used Row. $\endgroup$ – Mr.Wizard Sep 26 '12 at 11:37
  • $\begingroup$ @Mr.Wizard Thanks. $\endgroup$ – b.gates.you.know.what Sep 26 '12 at 11:48

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.