Demo 2.3

Plotting solution curves of solutions defined implicitly.

When the solutions of a first order differential equation are defined implicitly, as in the case with separable equations, the command ContourPlot can be used to graph the solutions.

?? ContourPlot

The meaning and usage of the options can as usual be found by selecting the command ContourPlot and pressing Command-shift-F to go to the Help Browser.  There we find, for example, that the option Contours ->{a,b,c,...} will graph the contours with the specific values a, b, c, ... of the constant, whereas the option Contours -> 15 will graph 15 equally spaced contours. 
Suppose the solution is given in the form g(x,y)=c.  We can then use the following model, with suitable editing for each example.

g[x_, y_] = ?

\(curves = 
      ContourPlot[g[x, y], {x, \(-3\), 3}, {y, \(-3\), 3}, 
					
        Axes -> True, Contours -> 15, 
					ContourShading -> False, 

        					ContourSmoothing -> True, 
		\ \ \ \ \ \ \ 
        AxesOrigin\  -> \ \(Automatic
					PlotPoints -> 25\)]\)

Example 1.                y' = (x^2)/(1 - (y^2))        on page 34 of the textbook

In this case the solution is given by

g[x_, y_] = (x^3) - 3  y + (y^3)

\(curves = 
      ContourPlot[g[x, y], {x, \(-3\), 3}, {y, \(-3\), 3}, 
				\ \ 
        Axes -> True, Contours -> 15, 
					ContourShading -> False, 

        					ContourSmoothing -> True, 
		\ \ \ \ \ \ \ 
        AxesOrigin\  -> \ \(Automatic
					PlotPoints -> 25\)]\)

If we wanted the solution curve for which y=2 when x=1, we plot the curve 
(x^3) - 3  y + (y^(3 ))=  g(1,2).

\(curves = 
      ContourPlot[g[x, y], {x, \(-3\), 3}, {y, \(-3\), 3}, 
					
        Axes -> True, Contours -> {g[1, 2]}, 
					
        ContourShading -> False, 
					ContourSmoothing -> True, 

        		\ \ \ \ \ \ \ 
        AxesOrigin\  -> \(Automatic
					PlotPoints -> 25\)]\)

Example 2.         y' = (y cos x)/(1+2 y^2)    on page 37

g[x_, y_] = Log[Abs[y]] + (y^2) - Sin[x]

\(curves = 
      ContourPlot[g[x, y], {x, \(-3\), 3}, {y,  .1, 3}, 
					
        Axes -> True, Contours -> 15, 
					ContourShading -> False, 

        					ContourSmoothing -> True, 
\ \ \ \ \ \ \ \ \ \ \ 
        AxesOrigin\  -> \ 
          \(Automatic		\ \ \ \ \ \ \ 
					PlotPoints -> 25\)]\)

The solution which has y=1 when x=0 is given by  g(x,y) = Log( |y | ) + (y^2)- Sin(y) = g(0,1).

\(curves = 
      ContourPlot[g[x, y], {x, \(-3\), 3}, {y,  .1, 3}, 
					
        Axes -> True, Contours -> {g[0, 1]}, 
					
        ContourShading -> False, 
					ContourSmoothing -> True, 

        		\ \ \ \ \ \ \ 
        AxesOrigin\  -> \ \(Automatic
					PlotPoints -> 25\)]\)

How to find the interval in which a solution is valid?

Remember  problem 11 done in class!
The solution to the equation  
            x dx + y (E^(-x)) dy  = 0  with   y(0) = 1                 
 is given by 
                            y = (Sqrt[2 (1 - x) (E^x) - 1]).  
We wish to know where this is well defined, so we plot the part inside the square root and then solve for the suitable roots between which it is positive.

Plot[2 (1 - x) (E^x) - 1, {x, -3, 3}]

We see that the roots are near -2 and 1.

Solve[2 (1 - x) (E^x) - 1 == 0, x]

This doesn't work because Solve can't solve most transcendental equations, and it solves this one with a function we don't know about.  NSolve works in this case, but not always.

NSolve[2 (1 - x) (E^x) - 1 == 0, x]

What we prefer is FindRoot which uses some form of Newton's method to find a root near a good guess.

?FindRoot

FindRoot[2 (1 - x) (E^x) - 1 == 0, {x, 1}]

FindRoot[2 (1 - x) (E^x) - 1 == 0, {x, -2}]

The solution is defined for  -1.67835 < x < 0.768039