Slope Fields and Integral curves.

Programming

\(\(\(
\)\(<< Graphics`PlotField`

    Needs["Graphics`Colors`"]

    Clear[PlotDirectionField]

    PlotDirectionField[
        f_, \ {x_, \ xmin_, \ xmax_}, 
	{y_, \ ymin_, \ 
          ymax_}, 
	\ opt___]\  := 
	
      PlotVectorField[\ {Sqrt[1/\((f^2\  + \ 1)\)], 
			f*
            Sqrt[1/\((f^2\  + \ 1)\)]}, \ {x, \ xmin, \ xmax}, 
		{y, \ 
          ymin, \ ymax}, Frame -> \ False, 
        Axes\  -> \ \ True, 
AxesOrigin -> \ {0, 
            0}, \ \ AxesLabel -> {x, y}, \ PlotPoints -> 20, 
        HeadWidth -> 0, \ opt]


    soln[x0_, \ y0_, \ {x_, xmin_, \ xmax_}, \ 
        y_]\  := \ \((y[x] /. \ 
          Flatten[NDSolve[{\(y'\)[x]\  == slope[x, y[x]], \ 
                y[x0]\  == \ y0}, \ 
              y[x], \ {x, xmin, \ 
                xmax}]\ ])\)


    IntegralCurves[slope_, \ 
        pointlist_, \ {x_, \ xmin_, \ xmax_}, \ {y_, \ ymin_, \ ymax_}, \ 
        opts___]\  := \ 
      Module[{field, i}, 
field\ \  = \ 
          PlotDirectionField[\ 
            slope[x, y]\ , \ {x, \ xmin, \ xmax}, \ 
		{y, \ ymin, \ 
              ymax}, opts, \ \ DisplayFunction\  -> \ 
              Identity
	]; 
solnlist = \ 
          Table[0, \ {i, \ 1, \ Length[pointlist]}]; 
For[
          i\  = \ 1, \ 
          i ≤ \ 
            Length[pointlist], \ \(i++\), 
solnlist[\([i]\)]\  = \ 
            soln[pointlist[\([i, 1]\)], \ 
              pointlist[\([i, 2]\)], {x, xmin - 1, \ xmax + 1}, \ 
              y]\ ]; 

solgraph\  = \ 
          Map[\((Plot[#, \ {x, \ xmin -  .5, \ xmax +  .5}, \ 
                  PlotRange\  -> \ {ymin, \ ymax}, \ 
                  PlotStyle\  -> {AbsoluteThickness[1], Red}, 
                  DisplayFunction\  -> \ Identity])\) &, \ 
            solnlist]; 


Show[{field, solgraph}, \ 
          DisplayFunction\  -> \ $DisplayFunction]

]

    \)\)\)

Exercise 10.3.2,  the slope field  (x + y)

Clear[solnlist,  solgraph, 
        slope];

    slope[x_,  y_]  :=   x + y;

    xmin  =  ymin  = -5;

    xmax  = ymax  =   5;

    dirfield PlotDirectionField[
        slope[x, y],  {x,  -5,  5},  {y,  -5, 5},  
        ScaleFactor ->   .4,  
        DisplayFunction  ->  Identity]

    soln1  =  soln[0, 0, {x, xmin,  xmax},  y];

    soln2  =  
        soln[-3, 1,  {x, xmin,  xmax},  y];

    soln3  =  
        soln[-1, 0,  {x, xmin,  xmax},  y];

    solgraph1  =  
      Plot[{soln1, soln2,  soln3},  {x,  xmin,  xmax},  
        PlotRange -> {ymin,  ymax},  
        PlotStyle  ->  {AbsoluteThickness[1], Red}]

pointlist  =  {{0, 0},  {-3, 1}};
IntegralCurves[slope,  
      pointlist,  {x,  -5,  5},  {y,  -5,  5},  
      ScaleFactor ->  .2]

Clear[solnlist,  solgraph, slope];
slope[x_,  y_]  :=   x + y;
pointlist  =  {{0, 0},  {-3, 1}};
IntegralCurves[slope,  
      pointlist,  {x,  -5,  5},  {y,  -5,  5},  
      ScaleFactor ->  .2]

Exercise 10.3.14 : Logistics and Gompertz

Clear[solnlist,  solgraph, slope];
slope[x_,  y_]  :=  y (2 -  y);
pointlist  =  {{1,  .5},  {1, 1}}
IntegralCurves[slope,  
      pointlist,  {t,  0,  5},  {y,  -1,  3},  
      ScaleFactor ->  .2]

Clear[solnlist,  solgraph, slope];
slope[x_,  y_]  :=  -y  *
          Log[y/2];
pointlist  =  {{1,  .5},  {1, 1}};
IntegralCurves[slope,  
      pointlist,  {t,  0,  5},  {y,  0.01,  3},  
      ScaleFactor ->  .2]