0

I'd like to plot the solution to the differential equation

$$\frac{d}{dx}y(x)=\frac{(y-1)^2}{(x+1)^2}$$

with initial value condition $y(0)=0$.

The solution is $$y(x)=\frac{x}{2x+1}$$

Clearly, this function is not defined for $x=-\frac{1}{2}$, a vertical asymptote in the graph of this function.

In Maple, I define the differential equation and plot the solution for the initial condition with commands:

ode := diff(y(x), x) = (y(x) - 1)^2/(x + 1)^2
with(DETools);
DEplot(ode2, y(x), x = -5 .. 5, [[y(0) = 0]]);

And the result is a plot with a warning. The warning is:

Warning, plot may be incomplete, the following errors(s) were issued:cannot evaluate the solution further left of -.49999997, probably a singularity

Plot of solution to differential equation with direction field

If I try to plot avoiding the vertical asymptote (singularity) in the graph, Maple doesn't plot anything at all, but does give the same warning as before:

DEplot(ode2, y(x), x = -5 .. -1, [[y(0) = 0]]);

How come Maple can't even plot when I avoid the singularity altogether? Also, how come it just can't plot the part of the function to the left of the singularity?

xoux
  • 4,913
  • Probably can but I am asking this question because I took it upon myself to learn to use Maple's differential equations capabilities exactly today, so I am not aware of how to do much. I can probably find out how to do what you said, but I am more interested to know why this particular command fails, and what is the recommended way to get around it, or if this command is even the most widely used one for this purpose. – xoux Aug 18 '21 at 20:16

1 Answers1

1

DEplot uses numerical methods, not the explicit solution formula, so it starts from $x=0$ and constructs an approximate solution step by step, and when things blow up at the singularity, there is no way for the numerical method (which doesn't know the explicit solution formula) to know where the solution is supposed to “come back” on the other side.

By the way, even if you know the solution formula, it's doubtful whether the part to the left of $x=-1/2$ can meaningfully be considered as a part of the solution to an initial value problem with $y(0)$ given, at least if you consider the ODE in the real domain. (If you let $x$ be complex, it's a different matter, since then you can go around the singularity in the complex plane.)

(And by the way too, there is also something funny going on when $(x,y)=(-1,1)$.)

Hans Lundmark
  • 53,395
  • y = 1 is a solution that is lost in the separation of variables technique used to solve the differential equation. What do you mean by (1,-1)? I agree that most likely the portion to the left of the singularity isn't useful for a given problem, but still, in fact it is part of the analytical solution. And even if we consider two solutions, the command DEplot is keeping one solution by accident ie error. Is there a better way to plot ODEs in Maple? – xoux Aug 19 '21 at 02:05
  • Sorry, I meant $(-1,1)$ (corrected now). The original ODE (as it's written) is undefined when $x=-1$, so your solution should be undefined there too. Your formula gives $y(-1)=1$, so the right-hand side in the ODE becomes $0/0$. But that's mostly nitpicking, since you can get around it by writing the ODE as $(x+1)^2 y' = (y-1)^2$ (although that ODE is still a little funny at $(x,y)=(-1,1)$, since the initial value $y(-1)=1$ gives infinitely many solutions, and $y(-1)=c$ with $c \neq 1$ gives none). – Hans Lundmark Aug 19 '21 at 04:03
  • 1
    Anyway, as long as you consider this initial value problem with real variables, the maximal interval of existence is $-1/2 < x$, and the left part of the graph is not really part of the solution. After all, a function such as $$y(x) = \begin{cases} 1, & x < -1/2,\[1ex] \dfrac{x}{2x+1}, & x > -1/2, \end{cases}$$ is just as much of an exact solution as the one you gave, and there is absolutely no way for a (real-variable) numerical method to select one rather than the other. – Hans Lundmark Aug 19 '21 at 04:11
  • 1
    If you want to plot the specific left part that you prefer, you either have to give the computer your exact formula, or specify it by giving an initial value at some $x<-1/2$. – Hans Lundmark Aug 19 '21 at 04:11