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]
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI 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]
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}}
*)
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]
7/10
instead of0.7
to get the solution. $\endgroup$"12.2.0 for Microsoft Windows (64-bit) (December 12, 2020)"
. $\endgroup$0.701
instead of0.7
for fun. It seems to freeze now. running at full CPU with 70 GB memory used so far. scary. $\endgroup$