# How to solve this NDSolve problem in Mathematica?

I found a confused problem in solving a ODE problems with NDSolve in Mathematica, the code is as follows:

I have tried 'Clear[Derivative]' and restart the kernel but these methods don't work.

Here is the question:

Here is my Mathematica code:

Clear[Derivative];

ClearSystemCache;

r = 0.3; a = 3; delta = 0.45; M0 = 0.975; T = 20;
u[t] = 0.5*l[t]*delta*M[t];
eql1 = M'[t] == r*M[t] Log[1/M[t]] - u[t]*delta*M[t];

eql2 = l'[t] == -2 *a *M[t] - l[t]* r *Log[1/M[t]] + l[t]*r -
l[t]*u[t]*delta;

condition = {M[0] == M0, l[T] == 0};

sol = NDSolve[Flatten@{{eql1, eql2}, condition}, {M, l}, {t, 0, 20}]


However this has problems, here is the problem result

Power::infy: Infinite expression 1/0. encountered.

Infinity::indet: Indeterminate expression 0. \[Infinity] encountered.

Power::infy: Infinite expression 1/0. encountered.

Infinity::indet: Indeterminate expression 0. \[Infinity] encountered.

Power::infy: Infinite expression 1/0. encountered.

General::stop: Further output of Power::infy will be suppressed during this calculation.

Infinity::indet: Indeterminate expression 0. ComplexInfinity encountered.

General::stop: Further output of Infinity::indet will be suppressed during this calculation.

NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.


The result picture is here

I can't figure out why there be "non-numerical value for a derivative at t == 0", there shouldn't be non-numerical value at t==0, the whole M[t] should be >0 when t<=20. I have spent a lot of time on this problem and still could not find an answer, please help me.

Best regards!

• Cross-posting - stackoverflow.com/questions/56023820/… - is rather frowned upon in the Stackiverse, leading to fragmentation, confusion and who-knows what else. Choose a site to ask your question at, delete it at any others. – High Performance Mark May 7 at 16:01
• You've got a boundary value problem. To see what's going on, convert it to an initial value problem by using condition = {l[0] == l0, M[0] == M0}and try to guess l0. I find that l0 needs to be at least 10^89 to avoid a singularity for 0 < t < 20. In that case l[20] = -57.6858. Increasing l0 to 10^154 and still l[20] = -1.30193, not reaching your desired boundary value of 0. Unfortunately beyond that, again NDSolve fails. But these crazy large numbers make me think there's something wrong with your equations or parameter values. – Chris K May 7 at 16:53