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.
Actually this should happen
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?
Answer
You could use Row
and ToString
:
Manipulate[
Row[{"f(", a, ") = ", a^2, " = ", ToString[a]^2}],
{a, 0, 10, 1}
]
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}
]
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}
]
Comments
Post a Comment