Re: evaluations in Plot in Manipulate?
- To: mathgroup at smc.vnet.net
- Subject: [mg90915] Re: evaluations in Plot in Manipulate?
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Tue, 29 Jul 2008 01:39:53 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <g6kc15$k4d$1@smc.vnet.net>
J Davis wrote: > I must be overlooking something simple in the way Mathematica handles > the arguments of Manipulate. > > Could someone expound on the contrast in behavior between the last > example below and the previous two? > > Clear[a, b, c, h]; > a = 1; > c = 1; > h[t_] = InverseLaplaceTransform[1/(a s^2 + b s + c), s, t] > > > Manipulate[ > Plot[Evaluate[ > InverseLaplaceTransform[1/(a s^2 + b s + c), s, t]], {t, 0, 10}, > PlotRange -> {{0, 10}, {-1, 1}}], {b, 0, 5}] > > (* works fine *) > > > Manipulate[ > Plot[-((E^((-(b/(2 a)) - Sqrt[b^2 - 4 a c]/(2 a)) t) - > E^((-(b/(2 a)) + Sqrt[b^2 - 4 a c]/(2 a)) t))/Sqrt[ > b^2 - 4 a c]), {t, 0, 10}, PlotRange -> {{0, 10}, {-1, 1}}], {b, 0, > 5}] > > (* works fine... I just copied and pasted the output of h[t] into the > Plot[...] *) > > > Manipulate[ > Plot[Evaluate[h[t]], {t, 0, 10}, > PlotRange -> {{0, 10}, {-1, 1}}], {b, 0, 5}] > > (* nothing... what am I missing? *) > > Doesn't Evaluate[h[t]] hold the evaluated form of h[t] (so that it is > computed just once) and then Plot simply substitutes a sequence of > numerical values into that evaluated form? If so, why is there no > output? Evaluate does nothing here since the function h[t] is defined with immediate assignment ("=" or *Set[]*), i.e. h[t] has already been evaluated when you defined it. (That's why you got an output when you evaluated the function. Contrast this behavior with the same definition but using delayed assignment ":=" or *SetDelayed[]*). Manipulate must "see" all the variables it manipulates in its first argument. Therefore, when one uses a function, the function must explicitly depends on all the variables that are going to be controlled by Manipulate[]. One possible way is as follows: Clear[a, b, c, h]; a = 1; c = 1; h[b_][t_] = InverseLaplaceTransform[1/(a s^2 + b s + c), s, t]; Manipulate[ Plot[h[b][t], {t, 0, 10}, PlotRange -> {{0, 10}, {-1, 1}}], {b, 0, 5}] Regards, -- Jean-Marc