Message Boards Message Boards

[?] Create animation of string vibration?

I am trying to animate a vibrating string. I have defined the solution as follows:

y = (8 y0/Pi^2) Sum[
    Sin[n Pi/2] Sin[n Pi x/L] Cos[n Pi c t/L], {n, 1, 1}] /. {y0 -> 
    0.1, L -> 0.5, c -> 20}

The Animate command I am using is this:

Animate[Plot[Evaluate[y], {x, 0, 0.5}], {t, 0, 0.1}, 
 AnimationRunning -> False]

I can't get anything to show up when I do this. It is just an empty animation. If I copy and paste the output of the definition of y into the Plot command, then it works. What am I doing wrong or what else do I need to do to get this to work?

Thank you!

POSTED BY: Gary Gray
2 Replies

That did it! I will have to remember that little tidbit. Thank you!

POSTED BY: Gary Gray

My guess is that the value of t in Animate is replaced into the Plot too soon, when the variable t is not yet present in the input. You can remedy this way:

With[{y = y},
 Animate[Plot[y, {x, 0, 0.5}], {t, 0, 0.1}, 
  AnimationRunning -> False]]

However, I would rather make the dependence on t,x explicit from the start:

Clear[y, t, x];
y[t_, x_] = (8 y0/Pi^2) Sum[
     Sin[n Pi/2] Sin[n Pi x/L] Cos[n Pi c t/L], {n, 1, 1}] /. {y0 -> 
     0.1, L -> 0.5, c -> 20};
Animate[Plot[y[t, x], {x, 0, 0.5}], {t, 0, 0.1}, 
 AnimationRunning -> False]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract