6
$\begingroup$

I am trying to solve the following differential equation $$p'(t)=0.7p(t)(1-\frac{p(t)}{750})-20$$ and has an initial value $p(0)=30$

eqn = p'[t] == 0.7 p[t]*(1 - p[t]/750) - 20
sol = DSolve[{eqn, p[0] == 30}, p[t], t]

But Mathematica gives an answer enter image description here. Why does this happen?

$\endgroup$
6
  • 6
    $\begingroup$ I can confirm this happening in 12.3 and 13.0 (both Windows), and in 13.2 (Wolfram Cloud). I suggest you report this to the Wolfram Technical Support. Meanwhile, use 7/10 instead of 0.7 to get the solution. $\endgroup$
    – Domen
    Dec 26, 2022 at 14:01
  • $\begingroup$ @Domen thanks for your response!!! I will report it $\endgroup$ Dec 26, 2022 at 14:05
  • $\begingroup$ Same error on "12.2.0 for Microsoft Windows (64-bit) (December 12, 2020)". $\endgroup$
    – Syed
    Dec 26, 2022 at 14:15
  • 4
    $\begingroup$ this is a good example why one should always use exact numbers with exact solvers. I keep saying this all the time but no body listens :) btw, try 0.701 instead of 0.7 for fun. It seems to freeze now. running at full CPU with 70 GB memory used so far. scary. $\endgroup$
    – Nasser
    Dec 26, 2022 at 17:04
  • 1
    $\begingroup$ @Nasser Mathematica 5.2 and 8.0.4 work fine with 0.701 instead of 0.7, as well: no freezes, no 70GB, in a moment. I agree that one should use exact numbers. But I believe that we see not only a bug, but also a regression. $\endgroup$
    – innaiz
    Dec 28, 2022 at 22:13

2 Answers 2

6
$\begingroup$

It's a pitfall of using inexact (floating-point) numbers with exact solvers.

eqn = p'[t] == 7/10 p[t]*(1 - p[t]/750) - 20;
sol = DSolve[{eqn, p[0] == 30}, p[t], t]
(*
{{p[t] -> (
   150 (95 + Sqrt[9345] - 95 E^(1/10 Sqrt[623/15] t) + 
      Sqrt[9345] E^(1/10 Sqrt[623/15] t)))/(
   483 + 5 Sqrt[9345] - 483 E^(1/10 Sqrt[623/15] t) + 
    5 Sqrt[9345] E^(1/10 Sqrt[623/15] t))}}
*)

Not sure if I'd count this as a bug, since it's sort of obvious (to me, anyway) that Mma will run into all kinds of algebraic trouble if things that should come out equal when given exact numbers do not cancel because of round-off error.

Alternatively, you could try arbitrary precision. Since it has round-off precision tracking, such numbers sometimes lead to success in exact solvers.

eqn = p'[t] == 0.7`16 p[t]*(1 - p[t]/750) - 20;
sol = DSolve[{eqn, p[0] == 30}, p[t], t]
(*
{{p[t] -> ((82687.2408479 + 
      0.*10^-8 I) + (720.248357811 + 0.*10^-10 I) E^(
     0.644463601248 t))/((2779.24964019 + 
      0.*10^-9 I) + (1.000000000000 + 0.*10^-13 I) E^(
     0.644463601248 t))}}
*)

We can see the problem in the OP is in solving the boundary conditions:

eqn = p'[t] == 0.7` p[t]*(1 - p[t]/750) - 20;
gensol = DSolve[{eqn}, p, t]
(*
{{p -> Function[{t}, (1.81899*10^-11 (3.95961*10^13 2.71828^(
          0.644464 t) + 
         1.63561*10^12 2.71828^(3.79605*10^13 C[1])))/(2.71828^(
       0.644464 t) + 2.71828^(3.79605*10^13 C[1]))]}}
*)

Solve[p[0] == 30 /. First@gensol, C[1]]
(*
Throw::sysexc: Uncaught SystemException returned to top level. Can be caught with Catch[\[Ellipsis], _SystemException].

SystemException["MemoryAllocationFailure"]
*)

Another workaround:

Solve[p[0] == 30 /. First@gensol /. N[E] -> E, C[1]]
sol = gensol /. First[%]
(*
Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.

{{C[1] -> 2.089*10^-13}}
*)
$\endgroup$
1
$\begingroup$

Surely a bug——but step back a little and replace all numerical parameters by symbols:

eqn = p'[t] == a p[t](1 - p[t] b) + c

And then solve the general equation:

DSolve[eqn, p[t], t]
$\endgroup$

Your Answer

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

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