It took me a while today to figure out that Manipulate
(used with Plot
) requires that the variable I'm manipulating be an actual parameter of the thing that I'm manipulating.
That is, if I have something like:
foo = Exp[2 x+y]
Manipulate[Plot[foo, {x, 0, 10}], {y, 0, 10}]
It will not work as desired, but if I have:
ffoo[x_, y_] := Exp[2 x+y]
Manipulate[Plot[ffoo[x, y], {x, 0, 10}], {y, 0, 10}]
It will.
I can't help but wonder; what is the general correct approach here? To me it feels slightly "wrong" that I should need to declare all the free variables for my statements as arguments. But maybe this is just something I should get over. In my case, it means I need to change, say, an arbitrary amount of places where I might call these to get various things (like eigenvectors with free parameters) and do a bunch of work converting them into function calls? Just because I want to use them in plots?
My actual approach was to write little "plot functions" for the particular bits I wanted to plot, and I then I did a little probably-inappropriate trick of just sneaking them into functions:
foofunc[a_, b_, c_] := Evalulate[foo]
(Knowing that foo
contains free variables named as "a", "b", etc...).
It seems, though, that there must be a better way of just asking Manipulate to consider implicit parameters (or whatever their formal name is; I tried a bit of searching and wasn't able to find anything about this; though I imagine it's fairly common).
Thanks for any advice.