3
$\begingroup$

I am trying to solve this DE:

DSolve[{r'[t] == r[t]^2/3 (1 - r[t]), r[0] == 2}, r[t], 
  t] // Simplify

For which I get the solution

InverseFunction[Log[1 - #1] - Log[#1] + 1/#1 &][
 1/2 + I \[Pi] - t/3 - Log[2]]

After plotting the solution

Plot[InverseFunction[Log[1 - #1] - Log[#1] + 1/#1 &][
  1/2 + I \[Pi] - t/3 - Log[2]], {t, 0, 20}, PlotRange -> All, 
 PlotPoints -> 100]

I get

enter image description here

However, the numerical solution using NDSolve results in:

enter image description here

How can I fix my DSolve result? I suspect the root finding process in the inverse function is a candidate? Because when I run

Table[{t, 
  InverseFunction[Log[1 - #1] - Log[#1] + 1/#1 &][
   1/2 + I \[Pi] - t/3 - Log[2]]}, {t, 0, 20, 0.5}]

some of the elements are not evaluated:

{{0., InverseFunction[Log[1 - #1] - Log[#1] + 1/#1 &][-0.193147 + 3.14159 I]}, {0.5, InverseFunction[Log[1 - #1] - Log[#1] + 1/#1 &][-0.359814 + 3.14159 I]},...

I am running MMA 10.3 on Windows 7.

$\endgroup$
  • $\begingroup$ Show more of your code, in particularly your first plot. Does PlotPoints -> 100 help? $\endgroup$ – David G. Stork Mar 17 '17 at 18:11
  • $\begingroup$ @DavidG.Stork Thanks for the suggestion. I edited my question. I don't think it's the plotting part. $\endgroup$ – MathX Mar 17 '17 at 18:24
4
$\begingroup$

Indeed, the numerical inversion of the DSolve solution,

s = DSolveValue[{r'[t] == r[t]^2/3 (1 - r[t]), r[0] == 2}, r[t], t] // Simplify
(* InverseFunction[Log[1 - #1] - Log[#1] + 1/#1 &][1/2 + I π - t/3 - Log[2]] *)

used to plot r as a function of t in the question is having difficulties. An alternative approach is to plot t as a function of r. First, extract the two arguments of the InverseFunction.

fun = Head[s][[1]][r]
(* 1/r + Log[1 - r] - Log[r] *)

arg = s[[1]]
(* 1/2 + I π - t/3 - Log[2] *)

equate the two, and solve for t.

a = (t /. Flatten@Solve[fun == arg, t]) // Expand
(* 3/2 + 3 I π - 3/r - 3 Log[2] - 3 Log[1 - r] + 3 Log[r] *)

Finally,

ParametricPlot[{a, r}, {r, 1, 2}, AspectRatio -> 1/GoldenRatio, 
    PlotRange -> {{0, 20}, All}, AxesOrigin -> {0, .95}]

enter image description here

which reproduces the numerical solution in the question, as desired.

$\endgroup$
  • $\begingroup$ This is great,thanks! I don't know why someone down voted? $\endgroup$ – MathX Mar 17 '17 at 21:13
  • 1
    $\begingroup$ @MathX Down-votes happen. Thanks for the kind words. $\endgroup$ – bbgodfrey Mar 17 '17 at 21:15
  • $\begingroup$ Actually, your solution makes Inverse Function usage much easier, and I'll be using it for many other problems I am facing. $\endgroup$ – MathX Mar 17 '17 at 21:16
4
$\begingroup$

It could also be view as a precision problem:

Plot[
 InverseFunction[Log[1 - #1] - Log[#1] + 1/#1 &][1/2 + I π - t/3 - Log[2]],
 {t, 0, 20},
 PlotRange -> All, PlotPoints -> 100, WorkingPrecision -> 50, Frame -> True]

Mathematica graphics

Of course InverseFunction is much slower than @bbgodfrey's parametric approach.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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