I'm just a beginner in Mathematica software. I have version 12.
I am looking for a program that will solve a prey-predator system with diffusion. My problem is that I tried a previously posted program, but the code is not compatible with Mathematica 12. Another problem is that I need to plot the solution as an animation to show the periodic motion. The program is next:
pts = 100;
t0 = 0;
t1 = 2;
tmax = 3000;
(*length of square*) L = 1;(*Time integration*) T = 8;(* Diffusion \
parameter for the prey*)d1 = 0.00028;(* Diffusion parameter for the \
predator*)d2 = 0.00028;(* Fertility parameter for the prey*)a = 1;(* \
Mortality parameter of the prey in the presence of predator*)b = 1;(* \
Fertility parameter of the predator*) c = 1;(* Fertility parameter of \
the predator in the presence of the prey*) d = 1;
(* Mortality parameter of the predator*) e = 1;
(*system of nonlinear PDE*)
pde = {D[u[t, x, y], t] ==
d1 (D[u[t, x, y], x, x] + D[u[t, x, y], y, y]) + a u[t, x, y] -
b u[t, x, y]*w[t, x, y],
D[w[t, x, y], t] ==
d2 (D[w[t, x, y], x, x] + D[w[t, x, y], y, y]) + c w[t, x, y] +
d u[t, x, y]*w[t, x, y] - e w[t, x, y]};
(*Newman boundary condition*)
bc = {(D[u[t, x, y], x] /. x -> -L) ==
0, (D[u[t, x, y], x] /. x -> L) ==
0, (D[u[t, x, y], y] /. y -> -L) ==
0, (D[u[t, x, y], y] /. y -> L) ==
0, (D[w[t, x, y], x] /. x -> -L) ==
0, (D[w[t, x, y], x] /. x -> L) ==
0, (D[w[t, x, y], y] /. y -> -L) ==
0, (D[w[t, x, y], y] /. y -> L) == 0};
(*initial condition*)
ic = {u[0, x, y] ==
Interpolation[
Flatten[Table[{x, y, RandomReal[]}, {x, -L, L, 2/pts}, {y, -L,
L, 2/pts}], 1]][x, y],
w[0, x, y] ==
Interpolation[
Flatten[Table[{x, y, RandomReal[]}, {x, -L, L, 2/pts}, {y, -L,
L, 2/pts}], 1]][x, y]};
(*ic={u[0,x,y]\[Equal]0,w[0,x,y]\[Equal]0};*)
eqns = Flatten@{pde, bc, ic};
sol = NDSolve[eqns, {u, w}, {t, 0, T}, {x, -L, L}, {y, -L, L},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid",
"MinPoints" -> pts, "MaxPoints" -> pts},
Method -> {"IDA", "ImplicitSolver" -> {"GMRES"}}}];
GraphicsGrid[Table[time = t0 + 2*t1;
DensityPlot[u[time, x, y] /. sol, {x, -L, L}, {y, -L, L},
ColorFunction -> "SunsetColors",
PlotLabel -> "t=" <> ToString[time], Ticks -> False], {t1, 0,
2}, {t0, 0, 2}], ImageSize -> 600]
(Animate[DensityPlot[
Evaluate[u[x, y, time] /. sol], {x, 0, L}, {y, 0, L},
FrameLabel -> {"x", "y"}, PlotPoints -> pts,
ColorFunctionScaling -> False], {time, 0, 3000}]
It appears the following warnings: NDSolve: Warning: boundary and initial conditions are inconsistent NDSolve: Warning: estimated initial error on the specified spatial grid in the direction of independent variable x exceeds prescribed error tolerance NDSolve: "Further output of
\!\(\*StyleBox[RowBox[{\"InterpolatingFunction\", \
\"::\", \"dmval\"}], \"MessageName\"]\) will be suppressed during \
this calculation."
Also the plot anime doesn't out.
If someone will help me, I will be very grateful.