0
$\begingroup$

I'm trying to make a streamplot of

$\qquad \frac{dy}{dx}=|y(x)|$

together with a couple of streamlines. I got stuck in the syntax. Can anyone help me out of it?

This what I've done:

sp = StreamPlot[{1, Abs[y[x]]}, {x, 0, 4}, {y[x], -4, 4}];
sol = y /. ParametricNDSolve[{y'[x] == Abs[y[x]], y[0] == a}, y, {x, 0, 4}, a]; 
Manipulate[
  Show[
    sp, 
    Plot[Evaluate[sol[a][x]], {x, 0, 4}, 
      PlotStyle -> Red, 
      PlotRange -> Full], 
    Epilog -> {Black, PointSize[0.02], Point[{0, a}]}], 
  {a, 0, 4}]
$\endgroup$
  • $\begingroup$ Where did you get stuck? Please post your code... $\endgroup$ – anderstood Mar 24 '18 at 12:04
  • $\begingroup$ This was most welcome :) Apparantely I have a steep learning curve. One question. In the code below how can I make thick red lines?sol = DSolve[{Q'[t] == 2 - 2/3*Q[t], Q[0] == q0}, Q[t], t] Show[Plot[ Evaluate[Table[Q[t] /. sol /. {q0 -> i}, {i, 0, 4, 1}]], {t, 0, 6}, PlotStyle -> {Red, Red, Red, Red}], StreamPlot[{1, 2 - 2/3*Q[t]}, {t, 0, 6}, {Q[t], 0, 6}, StreamMarkers -> "PinDart", StreamStyle -> Gray], AspectRatio -> 1, AxesLabel -> {"t", "Q(t)"}, PlotRange -> All] $\endgroup$ – runner Mar 24 '18 at 19:05
4
$\begingroup$

Use StreamPlot

sp = StreamPlot[{1, Abs[y]}, {x, 0, 2 Pi}, {y, 0, 2 Pi}]

enter image description here

sol[y0_?NumericQ] := 
 NDSolve[{D[y[x], x] == Abs[y[x]], y[0] == y0}, y, {x, -5, 5}]     

scp = Plot[Evaluate[{y[x]} /. sol[#] & /@ Range[0, 20, 0.3]], {x, -3, 3}, 
      PlotRange -> All, MaxRecursion -> 8, AxesLabel -> {"x", "y"}, PlotStyle -> Red]

Show[sp,scp ]

enter image description here

$\endgroup$
  • $\begingroup$ Ok, but I would like to see a use of e.g NDSolve together with some boundary conditions $\endgroup$ – runner Mar 24 '18 at 11:40
  • 5
    $\begingroup$ Then you should have mentioned that in your question, @user. $\endgroup$ – J. M. will be back soon Mar 24 '18 at 11:41

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