0
$\begingroup$

This is a problem of no special significance or difficulty. I trimmed it down to the minimum to demonstrate the frustrating behavior:

(DSolve[{ y''[t] + +y'[t] + v y[t] == Sin[w t], y[0] == 0, 
 y'[0] == 0}, y[t], t][[1, 1, 2]]) // FullSimplify

assume the above is the first action in a new kernel session

Manipulate[Plot[%1, {t, .01, 10}], {v, 2, 5}, {w, 6, 10}]

This gives something that works

repeat the exact above except name the solution, and then try to use that in the second expression:

vvv = (DSolve[{ y''[t] + +y'[t] + v y[t] == Sin[w t], y[0] == 0, 
 y'[0] == 0}, y[t], t][[1, 1, 2]]) // FullSimplify

Manipulate[Plot[vvv, {t, .01, 10}], {v, 2, 5}, {w, 6, 10}]

This last form gives a dumb, mute manipulate. Sliders move, but you get nothing - no output.

This is Mathematica 10.1.0 on OSX 10.11.6

If this is a bug, I'm speechless. If there's something I'm missing then I'd love to know what it is).

$\endgroup$
4
  • 1
    $\begingroup$ The second example works correctly because Manipulate is a scoping construct. I'm not sure why the first one works but I know this question was already asked here. It is just hard to search for % $\endgroup$
    – Kuba
    Aug 30, 2016 at 5:29
  • $\begingroup$ How are parameters evaluated for a Plot in Manipulate $\endgroup$
    – Kuba
    Aug 30, 2016 at 5:33
  • $\begingroup$ @kuba do you mean "the second one works incorrectly ? $\endgroup$
    – Paul_A
    Aug 30, 2016 at 14:01
  • $\begingroup$ No, this time I made no typo :P Manipulate scopes v and w before it sees v and w from vvv so at the end we have two sets of symbols. Have you read the link from my second topic? $\endgroup$
    – Kuba
    Aug 30, 2016 at 14:03

1 Answer 1

3
$\begingroup$

Use explicit arguments in vvv

vvv[t_, v_, w_] = 
  DSolve[{y''[t] + +y'[t] + v y[t] == Sin[w t], y[0] == 0, y'[0] == 0}, y[t], 
     t][[1, 1, 2]] // FullSimplify;

Manipulate[
 Plot[vvv[t, v, w], {t, .01, 10}],
 {v, 2, 5, Appearance -> "Labeled"},
 {w, 6, 10, Appearance -> "Labeled"}]

enter image description here

$\endgroup$
2
  • $\begingroup$ This "just makes it work" - does not explain why the second case (giving the solution a name, in this case vvv) makes the Manipulate mute/nonfunctional. $\endgroup$
    – Paul_A
    Aug 30, 2016 at 13:38
  • $\begingroup$ @Paul_A - @Kuba already told you that it is a scoping issue. Manipulate has the the attribute HoldAll which keeps the variables in vvv from being associated with the control variables unless the association is made by the use of explicit arguments in vvv[t, v, w]. Alternatively, you could move the definition of vvv inside the Manipulate. $\endgroup$
    – Bob Hanlon
    Aug 30, 2016 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.