# Flickering GIF in exporting Animation

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:

which is terrible!

• Try Cr[t_, p_] := NIntegrate[X[s, p].Transpose[X[s, p]], {s, 0, t}]; instead. Apr 10, 2019 at 17:34
• 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. Apr 10, 2019 at 19:39
• 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. Apr 11, 2019 at 16:27

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[].