Mathematica does not update the plot when a parameter is changed.

Hi,

Now I am running the wave equation using finite element method. Sometimes, when I change the parameters (for example, c value in the code) in the program, the result of graph does not change. It’s same. But after closing and restarting the Mathematica program, it looks that it works well, but just one time. When I change the parameters again, the results does not change again. Is that a bug in Mathematica ? or something wrong in my computer ?.

I am using V7.0 Mathematica.

Thank you very much in advance.

Here is the code.

Remove["Global\[OpenCurlyQuote]*"];
(*define the grid*)
Mx = 50.0; Lx = 1; Lt = 1; Mt = 100; c = 0.5;
\[CapitalDelta]x = Lx/Mx; \[CapitalDelta]t = Lt/Mt;
x[j_] := j \[CapitalDelta]x;
(*boundary conditions*)
z[0, n_] := 0; (* 0<= n *)
z[Mx, n_] := 0;
(*initial conditions*)
z[j_, 0] := 
  Exp[-1000 (x[j] - Lx/2)^2] Sin[x[j] \[Pi]]; (* 0<= j <= Mx *)
z[j_, 1] := \[CapitalDelta]t^2 c^2 /(2 \[CapitalDelta]x^2) ((z[j + 1, 
        0] - 2 z[j, 0] + z[j - 1, 0])) + z[j, 0];
z[j_, n_] := (z[j, n] = 
    2 z[j, n - 1] - 
     z[j, n - 
       2] + \[CapitalDelta]t^2 c^2 /(\[CapitalDelta]x)^2 ((z[j + 1, 
          n - 1] - 2 z[j, n - 1] + z[j - 1, n - 1]))) /; n >= 2
zsol = Interpolation[
   Flatten[Table[{j \[CapitalDelta]x, n \[CapitalDelta]t, 
      z[j, n]}, {j, 1, Mx - 1}, {n, 2, Mt}], 1]];
Plot3D[zsol[x, t], {x, 0, Lx}, {t, 0, Lt}, Mesh -> True, 
 PlotPoints -> 50, PlotRange -> All]

z[j_, n_] := (z[j, n] =... memoizes values, so they will not be recomputed. Better would be to make ity an explicit function of all parameters it uses, e.g. z[j_, n_, c_,...] := (z[j, n, c, ...] =...

See READ FIRST: How to post and use Wolfram Community for how to format code and text.

You could also reformulate the code using Manipulate to enable you to choose and change parameters.