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

Posted 8 years ago
6861 Views
|
3 Replies
|
1 Total Likes
|
 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] 
3 Replies
Sort By:
Posted 8 years ago
 You could also reformulate the code using Manipulate to enable you to choose and change parameters.
Posted 8 years ago
 See http://community.wolfram.com/groups/-/m/t/270507 for how to format code and text.
Posted 8 years ago
 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, ...] =...