[Date Index]
[Thread Index]
[Author Index]
wave eq. problem - Mathematica on the Mac quits!
*To*: mathgroup at yoda.physics.unc.edu
*Subject*: wave eq. problem - Mathematica on the Mac quits!
*From*: gaylord at ux1.cso.uiuc.edu
*Date*: Tue, 21 Apr 1992 04:38:07 -0500
===================================
===================================
Chris Haase writes:"
"Here is a short code that computes a numerical sulution to the wave
equation.
It is a modified version of a solution to the diffusion equation that was
sent to me. Anyway, without the For-loop, Mathematica responds with a
$RecursionLimit exceeded error. Is there a slick way to define the
recursion
function that will prevent such an error?
(* Waves by finite difference equation *)
Clear[i, n, u];
step=30;
(* The finite difference form of the wave equation:
the variable i represents the mesh position
the variable n represents the time step *)
u[i_, n_] := u[i, n] = u[i+1, n-1] + u[i-1,n-1] - u[i,n-2];
(* The boundary conditions and initializing profile *)
For[i=-10,i<=step+10,i++,Module[{j},
For[j=-10, j<=0, j++, u[i,j]=0;]
For[j=step,j<=step+10,j++, u[i,j]=0;]
]
]
u[14,-1] = 1.; u[14,0] = 1.;
u[15,-1] = 2.; u[15,0] = 2.;
u[16,-1] = 1.; u[16,0] = 1.;
(* Plot the initial and displaced profiles *)
plot1 = ListPlot[Table[u[i,0], {i, 1, step}],
PlotRange -> {{0,Step}, {-1,1}},
PlotJoined -> True,
AxesLabel -> {"x-position","amplitude"},
DisplayFunction -> Identity];
plot2 = ListPlot[Table[u[i, 4], {i, 1, step}],
PlotJoined -> True,
AxesLabel -> {"x-position","amplitude"},
DisplayFunction -> Identity];
Show[plot1,plot2,
PlotRange -> {{1, step}, {0,2}},
DisplayFunction -> $DisplayFunction];
============================
============================
eliminating the third For statement does not affect the program at all; it
seems to be unnecessary.
eliminating the second For statement produces the recursion depth
exceeded... message.
i then used the obvious bypass (p. 309 in the bible)
$RecursionLimit = X;
to get past the recusion limit and the following happened (using the
program given below)
for X = 2000 and 3000, the recursion depth message still occurred.
for X = 5000, I got a "application ' unknown' quit because of a type 28
error" message and Mathematica quit (the program causing this is given
below).
additional information: i ran this on a IIfx Mac with 20 Mbytes of RAM and
Mathematica 2.0.0 partitioned for 15 Mb under system 7.1.1.1.
=====================================
=====================================
(* Waves by finite difference equation *)
Clear[i, n, u];
$RecursionLimit = 5000;
step=30;
(* The finite difference form of the wave equation:
the variable i represents the mesh position
the variable n represents the time step *)
u[i_, n_] := u[i, n] = u[i+1, n-1] + u[i-1,n-1] - u[i,n-2];
(* The boundary conditions and initializing profile *)
For[i=-10,i<=step+10,i++,Module[{j},
]
]
u[14,-1] = 1.; u[14,0] = 1.;
u[15,-1] = 2.; u[15,0] = 2.;
u[16,-1] = 1.; u[16,0] = 1.;
(* Plot the initial and displaced profiles *)
plot1 = ListPlot[Table[u[i,0], {i, 1, step}],
PlotRange -> {{0,Step}, {-1,1}},
PlotJoined -> True,
AxesLabel -> {"x-position","amplitude"},
DisplayFunction -> Identity];
plot2 = ListPlot[Table[u[i, 4], {i, 1, step}],
PlotJoined -> True,
AxesLabel -> {"x-position","amplitude"},
DisplayFunction -> Identity];
Show[plot1,plot2,
PlotRange -> {{1, step}, {0,2}},
DisplayFunction -> $DisplayFunction];
Prev by Date:
**Re: Plotting x^(1/3), etc.**
Next by Date:
**mma animation summary**
Previous by thread:
**X11ps**
Next by thread:
**mma animation summary**
| |