3
$\begingroup$

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}]

enter image description here

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]]

enter image description here

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?

$\endgroup$
4
  • 2
    $\begingroup$ 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.) $\endgroup$
    – Michael E2
    Commented Apr 28, 2022 at 5:49
  • $\begingroup$ @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 $\endgroup$
    – yode
    Commented Apr 28, 2022 at 6:41
  • $\begingroup$ 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}$$ $\endgroup$
    – Michael E2
    Commented Apr 28, 2022 at 13:49
  • $\begingroup$ Probably not easy to get out of DSolve, though, unless it has improved its handling of singular solutions. (See previously linked answer.) $\endgroup$
    – Michael E2
    Commented Apr 28, 2022 at 13:50

2 Answers 2

4
$\begingroup$

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]]

Mathematica graphics

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]]

Mathematica graphics

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.

$\endgroup$
5
  • $\begingroup$ 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? $\endgroup$
    – yode
    Commented Apr 28, 2022 at 5:25
  • $\begingroup$ Could you give me a response please? $\endgroup$
    – yode
    Commented Apr 29, 2022 at 14:49
  • $\begingroup$ @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. $\endgroup$
    – Nasser
    Commented Apr 29, 2022 at 17:26
  • $\begingroup$ My sol is the solution of the differential equations indeed. Is the slope field it is in cannot plot correctly with MMA? $\endgroup$
    – yode
    Commented Apr 30, 2022 at 7:39
  • $\begingroup$ @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. $\endgroup$
    – Nasser
    Commented Apr 30, 2022 at 7:49
3
$\begingroup$

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[1][y][x] == -(1/2) Sqrt[-4 + y[x]^2] || 
     Derivative[1][y][x] == 1/2 Sqrt[-4 + y[x]^2])) 
     || 
     (y[x] >= 2 && 
    (Derivative[1][y][x] == -(1/2) Sqrt[-4 + y[x]^2] || 
     Derivative[1][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[1][y][x] == 0 || Derivative[1][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])}   *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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