1
$\begingroup$

Say I use some Mathematica procedures to find an interpolating function of two variables: $u(x,t)$. Is it possible to make a movie of this interpolating function, i.e. plot it on a certain line $x \in [0,L]$, while the time $t$ increases continously?

$\endgroup$
  • $\begingroup$ Yes, it is possible. You can animate it and export the animation to movie $\endgroup$ – Nasser Feb 3 '15 at 9:26
  • $\begingroup$ @Nasser I tried something like Animate[Plot[u[t, x], {x, 0, L}], {t, 0, tmax}], but it doesn't seem to work. Additionally, could you tell me how to export an animation to a movie? $\endgroup$ – Funzies Feb 3 '15 at 9:33
3
$\begingroup$

Update for comment to make the movie without the slider showing:

enter image description here

To make the above, used Manipulate, since little more flexible. Used Invisible Control. Here is the code.

p = Manipulate[
  Plot[u[x, t], {x, -4 Pi, 4 Pi}, Frame -> True, 
   FrameLabel -> {{"u(x)", None}, {"x", 
      Row[{"time", Spacer[2], AccountingForm[t, {2, 1}, 
     NumberPadding -> {"0", "0"}] , Spacer[2], "sec"}]}}, ImageMargins -> 10],
  Invisible[Control[{{t, 0, "time"}, 0, 20, .1, ImageSize -> 0}]],
  AutoRemove -> {1},
  Initialization :>
   (
    c = 1;
    u[x_, t_] := Sin[x - c t]
    )
  ]

and in new cell

SetDirectory[NotebookDirectory[]];
Export["foo.avi", p]

Original answer

Make an animation, for example, wave moving

c = 1;
u[x_, t_] := Sin[x - c t]
p = Animate[Plot[u[x, t], {x, -4 Pi, 4 Pi}], {t, 0, 20}];

Then export it

SetDirectory[NotebookDirectory[]];
Export["foo.mov", p]

enter image description here

added for comment:

Animate needs a parameter to use for the slider, as follows

sol = NDSolve[{
    D[u[t, x], t] == D[u[t, x], {x, 2}],
    u[0, x] == 0, u[t, 0] == Sin[t], u[t, 5] == 0},
   u, {t, 0, 20}, {x, 0, 5}];
Animate[Plot3D[Evaluate[u[t, x] /. sol], {t, 0, i}, {x, 0, 5}, 
  PlotRange -> All, ImagePadding -> 20, PerformanceGoal -> "Quality"], {i, .1, 20, .1}]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Your example works like a charm. However, if I try something like NDSolve[{D[u[t, x], t] == D[u[t, x], x, x], u[0, x] == 0, u[t, 0] == Sin[t], u[t, 5] == 0}, u, {t, 0, 10}, {x, 0, 5}] and then do p = Animate[Plot[u[t, x], {x, 0, 5}], {t, 0, 10}]; I get a blank movie.. $\endgroup$ – Funzies Feb 3 '15 at 9:55
  • $\begingroup$ @Funzies you did not do it correctly. added the example. Now just put p=Animnate.... as before, and export it. Should work $\endgroup$ – Nasser Feb 3 '15 at 10:06
  • $\begingroup$ Thanks a lot, you were very helpful! $\endgroup$ – Funzies Feb 3 '15 at 10:11
  • $\begingroup$ @Nasser How can the Animator bar be eliminated from the movie? Thanks. $\endgroup$ – bbgodfrey Feb 3 '15 at 17:59
  • $\begingroup$ @bbgodfrey yes. I used Manipulate, which is little more flexible to make the move. Please see update $\endgroup$ – Nasser Feb 3 '15 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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