Message Boards Message Boards

0
|
8176 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:

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

Posted 10 years ago

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]
POSTED BY: hwoarang Polar
3 Replies

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

POSTED BY: S M Blinder

See http://community.wolfram.com/groups/-/m/t/270507 for how to format code and text.

POSTED BY: Bruce Miller

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, ...] =...

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract