1
$\begingroup$

I'm first time use Mathematica and here is my trying of solving equation

b = 2.1;
a = 1.5;
g = 1.15;
d = 0.01;
k = 25;
l = 1;
L = 6;

r[t_] := b/a - E^(-a*(t - 1))*(b/a - g);
eqn = D[i[x, t], t] == d*D[i[x, t], {x, 2}] + r[t]*i[x, t]*(1 - i[x, t]/k);
ufun = 
  NDSolve[
    {eqn, i[x, 1] == 0, D[i[x, t], x] == 0 /. x -> l, D[i[x, t], x] == 0 /. x -> L}, 
    i[x, t], {t, 1, 50}, {x, l, L}, 
    Method -> "ExplicitRungeKutta"];

After fixing all errors this code was accepted but did nothing. So, Plot isn't show anything

list = 
  Table[Plot[ufun[i[x, t]], {x, 1, 6}, PlotRange -> {0.9, 6.5}], {t, 1, 50, 1}];
ListAnimate[list];

I know that I'm doing something wrong, but I don't know, what. So, here are the questions:

1) What's wrong with this code?

2) How can I use cubic spline interpolation to set initial conditions?

I tried this:

...
pts = {{1., 6.}, {2., 2.}, {3., 2.1}, {4., 1.}, {5., 0.9}, {6., 0.8}};
f[x_] := BSplineFunction[pts];
...
ufun = NDSolve[{eqn, i[x, 1] == f[x] ...
$\endgroup$
4
  • $\begingroup$ This Plot3D[i[x, t] /. ufun, {t, 1, 50}, {x, l, L}] should plot the solution to your PDE, but that plot looks like it is just zero. This Table[(i[x, t] /. ufun[[1]]), {x, 1, 6}, {t, 1, 50}] shows you that your solution is always almost exactly zero. Even if I change your code to d=20 the result is still just zero. Does that give you any idea where to start looking? $\endgroup$
    – Bill
    Commented Nov 7, 2018 at 5:57
  • $\begingroup$ Thanks, I finally found answer for my first question with your help. Anybody know something about second question? $\endgroup$ Commented Nov 7, 2018 at 6:30
  • $\begingroup$ It will be helpful if you write explicitly what initial condition do you need. Presently it is most simple. I assume it should be more complex, right? $\endgroup$ Commented Nov 7, 2018 at 7:51
  • $\begingroup$ I need to interpolate the initial discrete data (for x=1,2,3,4,5,6) at the moment t=1 for continuous and smooth function that I can set to i[x, 1] $\endgroup$ Commented Nov 7, 2018 at 10:07

1 Answer 1

2
$\begingroup$

It is necessary to agree on the initial and boundary conditions and use the method BDF and data interpolation, then the solution converges

b = 2.1;
a = 1.5;
g = 1.15;
d = 0.01;
k = 25;
l = 1;
L = 6;
pts = {{1., 6.}, {2., 2.}, {3., 2.1}, {4., 1.}, {5., 0.9}, {6., 0.8}};
f = Interpolation[pts, InterpolationOrder -> 2];

r[t_] := b/a - E^(-a*(t - 1))*(b/a - g);
eqn = D[i[x, t], t] == 
   d*D[i[x, t], {x, 2}] + r[t]*i[x, t]*(1 - i[x, t]/k);
ufun = NDSolve[{eqn, i[x, 1] == f[x], 
   D[i[x, t], x] == f'[x] /. x -> l, 
   D[i[x, t], x] == f'[x] /. x -> L}, i[x, t], {t, 1, 10}, {x, l, L}, 
  Method -> "BDF"]
ContourPlot[i[x, t] /. ufun, {x, l, L}, {t, 1, 10}, PlotRange -> All, 
 Contours -> 20, ColorFunction -> "TemperatureMap", 
 PlotLegends -> Automatic, FrameLabel -> {"x", "t"}]

fig1

$\endgroup$
2
  • $\begingroup$ Thanks a lot. Also, is it possible to use more smooth interpolation, like cubic spline? $\endgroup$ Commented Nov 7, 2018 at 14:00
  • 1
    $\begingroup$ Data is not enough to interpolate a cubic spline. But you can put f = Interpolation [pts, InterpolationOrder -> 3]. Solution of the equation will change a little. $\endgroup$ Commented Nov 7, 2018 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.