Question: handling singularity when making slope field plot

sometimes when using DEtools:-DEplot, it gives warning on singularity in solution and only plots part of the solution (on top of the slope field) on one side of the singularity.  But the plot() command works and there is no such warning, and it plots the solution on both sides of the singularity on its own.

Is there a way to make DEtools:-DEplot do the same? In this case the solution is y(x) = -1/x + 6 and x=0 is singularity. Here is worksheet showing such an example

It seems DEtools:-DEplot does not use same internal plotting code that plot used to superimpose the solution plot on top of the slope field plot? 

interface(version);

`Standard Worksheet Interface, Maple 2025.2, Windows 10, November 11 2025 Build ID 1971053`

ode:=diff(y(x),x) = 1/x^2;
IC:=y(1) = 5;
sol:=dsolve([ode,IC]);
p:=plot(rhs(sol),'axes'='boxed','labels'=[x,y(x)],'axis'=['gridlines'=['color'='lightblue']],'color' = 'red');

diff(y(x), x) = 1/x^2

y(1) = 5

y(x) = -1/x+6

 

 

T:=rhs~(indets(p, identical("originalview")=anything))[];     
from_x := op(1,T[1]);
to_x   := op(2,T[1]);
from_y := op(1,T[2]);        
to_y   := op(2,T[2]);

[-.1000000000 .. .2500000000, -30. .. 40.]

-.1000000000

.2500000000

-30.

40.

DEtools:-DEplot(ode,[y(x)],x=from_x..to_x,y=from_y ..to_y ,[IC],
                'dirfield'=[15,15],
                'labels'=[x,y(x)],
                'axes' = 'boxed',                
                'arrows'='smalltwo', #'curve',
                'color' = 'blue',#color of arrows
                'linecolor'='red',#color of solution
                'obsrange'=false
                );

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

 


 

Download handling_signularity_in_slope_field.mw

One possibility I can do is to plot slope field without passing it initial conditions. THis makes it not plot the solution and only show the slope field. Then use display to superimpse the solution plot from plot() comamnd. And this now works, like this:


 

interface(version);

`Standard Worksheet Interface, Maple 2025.2, Windows 10, November 11 2025 Build ID 1971053`

ode:=diff(y(x),x) = 1/x^2:
IC:=y(1) = 5:
sol:=dsolve([ode,IC]):
p1:=plot(rhs(sol),'axes'='boxed','labels'=[x,y(x)],'axis'=['gridlines'=['color'='lightblue']],'color' = 'red'):

 

 

T:=rhs~(indets(p, identical("originalview")=anything))[];     
from_x := op(1,T[1]):
to_x   := op(2,T[1]):
from_y := op(1,T[2]):        
to_y   := op(2,T[2]):

[-.1000000000 .. .2500000000, -30. .. 40.]

p2:=DEtools:-DEplot(ode,[y(x)],x=from_x..to_x,y=from_y ..to_y ,
                'dirfield'=[15,15],
                'labels'=[x,y(x)],
                'axes' = 'boxed',                
                'arrows'='smalltwo', #'curve',
                'color' = 'blue',#color of arrows
                'linecolor'='red',#color of solution
                'obsrange'=false
                );

plots:-display([p1,p2])

 

 

Download handling_signularity_in_slope_field_V1.mw

But before I change my code to do this, I thought to ask in case there is an option in DEtools:-DEplot which makes it handle the solution plot as is like plot() did. If not, then I can use display.

 

 

Please Wait...