Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

A question about Manipulate command in Mathematica

  1. Oct 3, 2009 #1
    This works:
    Code (Text):
    Manipulate[Plot[E^(n*x), {x, -10, 10}], {n, 1, 10}]
    This doesn't:
    Code (Text):
    f[x_] := E^(n*x);
    Manipulate[Plot[f[x], {x, 1, 10}], {n, 1, 10}]
     
    Why?
    (I used Mathematica 7.0)
     
  2. jcsd
  3. Oct 3, 2009 #2

    CompuChip

    User Avatar
    Science Advisor
    Homework Helper

    Then again, this does:
    Code (Text):

    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 (Text):

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: A question about Manipulate command in Mathematica
Loading...