0
$\begingroup$

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

$\endgroup$
  • $\begingroup$ 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! $\endgroup$ – Michael E2 Dec 2 '15 at 3:57
2
$\begingroup$

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])]
$\endgroup$
  • $\begingroup$ 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 ? $\endgroup$ – user36036 Dec 2 '15 at 5:04
  • $\begingroup$ See my edit above. Use Show. $\endgroup$ – Lotus Dec 2 '15 at 5:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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