4
$\begingroup$

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?

$\endgroup$

2 Answers 2

5
$\begingroup$

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]

gif

$\endgroup$
3
$\begingroup$

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]

enter image description here

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

Your Answer

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