Change values in equation with slider

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?

-

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}
]


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