# Making a movie from an interpolating function

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?

• Yes, it is possible. You can animate it and export the animation to movie – Nasser Feb 3 '15 at 9:26
• @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? – Funzies Feb 3 '15 at 9:33

Update for comment to make the movie without the slider showing: 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, AccountingForm[t, {2, 1},
NumberPadding -> {"0", "0"}] , Spacer, "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]


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] 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}] • 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.. – Funzies Feb 3 '15 at 9:55
• @Funzies you did not do it correctly. added the example. Now just put p=Animnate.... as before, and export it. Should work – Nasser Feb 3 '15 at 10:06
• Thanks a lot, you were very helpful! – Funzies Feb 3 '15 at 10:11
• @Nasser How can the Animator bar be eliminated from the movie? Thanks. – bbgodfrey Feb 3 '15 at 17:59
• @bbgodfrey yes. I used Manipulate, which is little more flexible to make the move. Please see update – Nasser Feb 3 '15 at 19:08