# Is there any way we can draw its slope field without solving the differential equation?

Some equations are difficult to solve, so perhaps we can plot a function of the equation to see roughly how the solution looks. The same is true for differential equations, where we can observe the integral curve by drawing its slope field.

I have a differential equation: $$y^2=4+4\left(\frac{dy}{dx}\right)^2$$ Then I can get $$y'=±\sqrt{\frac{y^2-4}{4}}$$. So I want to plot the $$+$$ part:

StreamPlot[{1, Sqrt[((y^2 - 4)/4) ]}, {x, -1, 5}, {y, 0, 4}] But actually I know the solution of this differential equations from here is:

sol[x_]:=1/2 (c E^(x/2)+(4 E^(-x/2))/c)


And then something strange happened:

c = 1;
sol[x_] := 1/2 (c E^(x/2) + (4 E^(-(x/2)))/c);
Show[StreamPlot[{1, Sqrt[1/4 (y^2 - 4)]}, {x, -1, 5}, {y, 0, 5}],
Plot[Evaluate[sol[x]], {x, -1, 6}, AxesOrigin -> {0, 0},
PlotStyle -> Blue]] It looks like this slope field is only correct within a certain range (e.g. the right-hand side). But exactly where the turning point is, we may need sol to determine that. But the purpose of my drawing the slope field is to know the information of sol, how can I in turn draw the slope field by the information of sol? This is confusing me. So I ask here.

Is there any way I can draw the direction field correctly without any information from sol?

• Your sol[x_] is not a solution to the + part, no? It's a solution to the orginal DE, though, yes? (The direction field is two-valued, as you point out, but you draw only one of the values....It's unclear to me why it's confusing.) Apr 28, 2022 at 5:49
• @MichaelE2 In fact, I wanted to draw all the parts where the sol[x] was (including the + and - parts) but I found I needed the sol[x] itself to know which part of the slope field was correct and which part was wrong. This seems to defeat my original purpose of drawing the slope field. So I feel confused
– yode
Apr 28, 2022 at 6:41
• For each $x_0$, at the initial condition $(x_0, y_0=2)$, there are three solutions, including the singular solution $y(x)=2$. A similar thing is happening in my answer here, Fig. 3, bottom left, where I show the two-sheeted cover of the slope field (if you will allow the integral curves to represent the slopes as in StreamPlot). A solution to the + part has the form $$y(x)= \begin{cases} \left(e^{-\frac{1}{2} \left(x-x_0\right)}+e^{\frac{1}{2} \left(x-x_0\right)}\right) & x>x_0 \\ 2 & x\le x_0 \end{cases}$$ Apr 28, 2022 at 13:49
• Probably not easy to get out of DSolve, though, unless it has improved its handling of singular solutions. (See previously linked answer.) Apr 28, 2022 at 13:50

But actually I know the solution of this differential equations is:

There are more than one solution.

You picked the wrong solution to try. Using the other one gives what you were expecting to show:

c = 1;
sol[x_] := 1/2*(Exp[-1/2*x]^2*c^2 + 4)/Exp[-1/2*x]/c;
Show[StreamPlot[{1, Sqrt[1/4 (y^2 - 4)]}, {x, -1, 5}, {y, 0, 5}],
Plot[Evaluate[sol[x]], {x, -1, 5}, AxesOrigin -> {0, 0},
PlotStyle -> Blue]] To see the other region this works (note need to use c=-1 for it to show up). Now $$y$$ is limited to {y, 0, -5}

c = -1;
sol[x_] := 1/2*(Exp[-1/2*x]^2*c^2 + 4)/Exp[-1/2*x]/c;
Show[StreamPlot[{1, -Sqrt[1/4 (y^2 - 4)]}, {x, -1, 5}, {y, 0, -5}],
Plot[Evaluate[sol[x]], {x, -1, 5}, AxesOrigin -> {0, 0},
PlotStyle -> Blue]] Other solutions are $$y=2$$ and $$y=-2$$. From existence and uniqueness theory for first order ode, the general solution exist for $$y>2$$ or $$y<-2$$. The other two solutions are singular solutions.

• How do you get that "the other one" you said?? My sol is the solution of the differential equations indeed. Is the slope field it is in cannot plot with MMA?
– yode
Apr 28, 2022 at 5:25
• Could you give me a response please?
– yode
Apr 29, 2022 at 14:49
• @yode oh I did not notice you had question. I simply solved this using Maple. It showed 2 general solutions. I tried one, did not work/match the slope curve plot, and then tried the second, which matched. So I used the second one. I can post the code and the output if you want. Apr 29, 2022 at 17:26
• My sol is the solution of the differential equations indeed. Is the slope field it is in cannot plot correctly with MMA?
– yode
Apr 30, 2022 at 7:39
• @yode, there might be some issue here. I see you had discussion with Michael about this also. I used the slopefiled you had, and just matched it with the solution by Maple. I am sorry, but the above is all what I can provide on this now as I have to spend time on other things. Hope you can find solution that satisfies your needs. Apr 30, 2022 at 7:49

Get an overview of the solutions in the reals with Reduce.

eq = y[x]^2 == 4 + 4 y'[x]^2;

red = Reduce[eq, y'[x], Reals]

(*   (y[x] <= -2 &&
(Derivative[y][x] == -(1/2) Sqrt[-4 + y[x]^2] ||
Derivative[y][x] == 1/2 Sqrt[-4 + y[x]^2]))
||
(y[x] >= 2 &&
(Derivative[y][x] == -(1/2) Sqrt[-4 + y[x]^2] ||
Derivative[y][x] == 1/2 Sqrt[-4 + y[x]^2]))          *)


Which gives all the solutions @Nasser showed perfectly, even the two singular one

{red /. y[x] -> -2, red /. y[x] -> 2} // Union

(*   {Derivative[y][x] == 0 || Derivative[y][x] == 0}   *)


Get the two general solutions via DSolve

ysol[aa_, bb_] = y /. DSolve[{eq, y[aa] == bb}, y, x]

Through[ysol[aa, bb][x]] //
Union[#, SameTest -> (Simplify[#1 - #2,
Assumptions -> Element[{aa, bb}, Reals]] === 0 &)] &

(*   {-((E^(-x/2) (-2 E^aa + bb^2 E^aa + 2 E^x -
bb E^(aa/2) Sqrt[(-4 + bb^2) E^aa]))/(-bb E^(aa/2) +
Sqrt[(-4 + bb^2) E^aa])),
(E^(-x/2) (-2 E^aa + bb^2 E^aa + 2 E^x +
bb E^(aa/2) Sqrt[(-4 + bb^2) E^aa]))/(
bb E^(aa/2) + Sqrt[(-4 + bb^2) E^aa])}   *)