Error animating a 3d parametric plot of a sum

I am trying to animate a sum together with a circle (specifically the vector field $$(r \sin \theta , r \cos \theta, u(r,t))$$ using Animate and ParametricPlot3D in the following code.

Clear["Global*"]
f[r_] := 1 - r^4
a = 1;
c = 1;

x0m[m_] := N[BesselJZero[0, m]]
omega0[m_] := c/a*x0m[m]
d[m_] := (Integrate[
r*BesselJ[0, (x0m[m]*r)/(a*c)]*f[r], {r, 0, a}])/(Integrate[
r*(BesselJ[0, (x0m[m]*r)/(a*c)])^2, {r, 0, a}])
u[r_, t_, mmax_] :=
Sum[d[m]*BesselJ[0, (x0m[m]*r)/(a*c)]*Cos[omega0[m]*t], {m, 1, mmax}]

Animate[ParametricPlot3D[{r*Cos[theta], r*Sin[theta], u[r, t, 5]}, {r,
0, 1}, {theta, 0, 2*π}, PlotRange -> {-1.2, 1.2},
BoundaryStyle -> Directive[Red, Thick],
ColorFunction -> "SolarColors", Mesh -> True], {t, 0, 10, 0.0001}]


However Animate does nothing, although Mathematica computes the sum. I think the problem is the ParametricPlot3D inside Animate but I don't understand what is wrong with it. Can you help?

The following will create a .gif file with the animation in the same path where you have saved your notebook. Note that I changed the animation step, but you can change it back.

f[r_] := 1 - r^4
a = 1;
c = 1;
x0m[m_] := N[BesselJZero[0, m]]
omega0[m_] := c/a*x0m[m]
d[m_] := (Integrate[
r*BesselJ[0, (x0m[m]*r)/(a*c)]*f[r], {r, 0, a}])/(Integrate[
r*(BesselJ[0, (x0m[m]*r)/(a*c)])^2, {r, 0, a}])
u[r_, t_, mmax_] :=
Sum[d[m]*BesselJ[0, (x0m[m]*r)/(a*c)]*Cos[omega0[m]*t], {m, 1, mmax}]

dat = Animate[
ParametricPlot3D[
Evaluate@{r*Cos[theta], r*Sin[theta], u[r, t, 5]}, {r, 0,
1}, {theta, 0, 2*π}, PlotRange -> {-1.2, 1.2},
BoundaryStyle -> Directive[Red, Thick],
ColorFunction -> "SolarColors", Mesh -> True], {t, 0, 10, 1},
AnimationDirection -> ForwardBackward]

SetDirectory@NotebookDirectory[]
Export["gif.gif", dat]


Use the same Evaluate setting as the answer by @bmf or define g[r_, t_, theta_] outside to the Animate.

And we replace := by = and replace Integrate by NIntegrate in order to faster the calculate.(also maybe use PerformanceGoal -> "Speed" )

Clear["Global*"];
f[r_] = 1 - r^4;
a = 1;
c = 1;
x0m[m_] = N@BesselJZero[0, m];
omega0[m_] = c/a*x0m[m];
d[m_] := (NIntegrate[
r*BesselJ[0, (x0m[m]*r)/(a*c)]*f[r], {r, 0, a}])/(NIntegrate[
r*(BesselJ[0, (x0m[m]*r)/(a*c)])^2, {r, 0, a}]);
u[r_, t_, mmax_] :=
Sum[d[m]*BesselJ[0, (x0m[m]*r)/(a*c)]*Cos[omega0[m]*t], {m, 1,
mmax}];
g[r_, t_, theta_] = {r*Cos[theta], r*Sin[theta], u[r, t, 5]};
Animate[ParametricPlot3D[
g[r, t, theta], {r, 0, 1}, {theta, 0, 2*π},
PlotRange -> {-1.2, 1.2}, BoundaryStyle -> Directive[Red, Thick],
ColorFunction -> "SolarColors", Mesh -> True,
PerformanceGoal -> "Quality"], {t, 0, 10, 0.0001},
AnimationRate -> .1, ControlPlacement -> Bottom]


• (+1) because... the need for speed :-)
– bmf
Commented Apr 7, 2022 at 21:43
• @bmf Thanks (+1) Commented Apr 7, 2022 at 21:45