# Plot the evolution of an approximation - Animate

Here's the code

Clear[f, g]
f[x_] := x^2;
g[i_Integer, 1] := g[i, 1] = f[i];
g[50, _] = g[0, _] = 0;(*initial and final condition*)
g[i_Integer, j_Integer] :=
g[i, j] = Max[0.5*(g[i - 1, j] + g[i + 1, j - 1]), f[i]];
ListPlot[Table[{i, g[i, #]}, {i, 0, 50}] & /@ {1, 10}]


Now what I want to do is to make a plot of the evolution of $g_i^k$ in terms of k. I want to animate it for $k=0,.....100$. How Can I do that ?

And I want to display the fixed curve $f(x)=x²$ in the animation, how to do that ? Thanks

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Commented Dec 2, 2015 at 3:57

If I understand you correctly, this is what I would do:

 ListAnimate[
ListPlot[Table[{i, g[i, #]}, {i, 0, 50}],
PlotRange -> {{1, 60}, {0, 3000}}] & /@ Range[1, 100, 10]]


Use Show to combine the plot for x^2 with each ListPlot and then ListAnimate the whole set:

ListAnimate[
Show /@ ({ListPlot[Table[{i, i^2}, {i, 0, 50}], Joined -> True],
ListPlot[Table[{i, g[i, #]}, {i, 0, 50}],
PlotRange -> {{1, 60}, {0, 3000}}]} & /@ Range[1, 100, 10])]

• It works but I forgot to ask a question.I also want to display with the animation a fixed curve that is $f(x)=x²$ how to do that ? Commented Dec 2, 2015 at 5:04
• See my edit above. Use Show. Commented Dec 2, 2015 at 5:22