2
$\begingroup$

I am trying to export an Animate object to a GIF file, but the saved GIF file keeps flickering. How do I fix this?

X[t_, p_] = Table[{Sin[t + (k*\[Pi])/p]}, {k, 0, 8}];
Cr[t_, p_] = 
  FullSimplify[Integrate[X[s, p].Transpose[X[s, p]], {s, 0, t}]];
Eig2[t_, p_] := Eigenvectors[Cr[t, p]][[1]]
Export["cm.gif", 
 Animate[GraphicsGrid[{{MatrixPlot[Cr[2*\[Pi], u], 
      ImageSize -> {350, 350}], Plot[X[t, u], {t, 0, 2 \[Pi]}], 
     ListPlot[Eig2[2 \[Pi], u]]}}], {u, 0.01, 1, 0.01}]]

produces:

enter image description here

which is terrible!

$\endgroup$
3
  • 1
    $\begingroup$ Try Cr[t_, p_] := NIntegrate[X[s, p].Transpose[X[s, p]], {s, 0, t}]; instead. $\endgroup$ Apr 10, 2019 at 17:34
  • 1
    $\begingroup$ I haven't looked at Henrik's solution, maybe this problem is already solved, but I just want to say that the flickering is definitely because the code fails for some values of u. You can see the red error rectangle for the frames that fail. The right question isn't why the animation flickers, but why the code fails for some u. $\endgroup$
    – C. E.
    Apr 10, 2019 at 19:39
  • $\begingroup$ When I ran this code exactly as is the gif came out fine. This may be a problem with the dynamic updating. Here is a similar problem occurring with manipulate. When the program runs is your CPU or memory maxing out? If this is the case I think that as @Henrik pointed out there may be places to optimize your code. $\endgroup$
    – cphys
    Apr 11, 2019 at 16:27

1 Answer 1

1
$\begingroup$

I suggest

ClearAll[X, Cr, Eig2];
X[t_, p_] := Table[{Sin[t + (k Pi)/p]}, {k, 0, 8}];
Cr[t_, p_] := Cr[t, p] = 
   NIntegrate[X[s, p].Transpose[X[s, p]], {s, 0, t}] // Quiet;
Eig2[t_, p_] := Eigenvectors[Cr[t, p]][[1]];

Then try

Animate[GraphicsGrid[{{MatrixPlot[Cr[2 Pi, u], ImageSize -> {350, 350}],
  Plot[X[t, u], {t, 0, 2 Pi}], ListPlot[Eig2[2 Pi, u]]}}],
    {u, 0.01, 1, 0.01}, AnimationRepetitions -> 1]

a few times to see if you like the animation. Then wrap it in Export[].

$\endgroup$

Your Answer

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

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