A question about Manipulate command in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter kindlychung
  • Start date Start date
  • Tags Tags
    Mathematica
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 4K views
kindlychung
Messages
10
Reaction score
0
This works:
Code:
Manipulate[Plot[E^(n*x), {x, -10, 10}], {n, 1, 10}]

This doesn't:
Code:
f[x_] := E^(n*x);
Manipulate[Plot[f[x], {x, 1, 10}], {n, 1, 10}]

Why?
(I used Mathematica 7.0)
 
Physics news on Phys.org
Then again, this does:
Code:
Subscript[f, n_][x_] := E^(n*x);
Manipulate[Plot[Subscript[f, n][x], {x, 1, 10}], {n, 1, 10}]

Apparently the n in the definition of f[x] is not the same n as that in Manipulate. When you execute
Code:
Subscript[f, n_][x_] := E^(n*x);
Manipulate[Plot[Subscript[f, n][x], {x, 1, 10}] // Hold, {n, 1, 10}]
you will see that the running n is a temporary variable (FE`n$$27, or something like that) different from the Global`n that f[x] uses. When you pass n to f[x] as well, by defining fn[x] or f[n, x], it works.