# Proper way to produce StreamPlot

I have faced with problem of not completely correct phase trajectories of ODE, which was produced by StreamPlot.

Next following code ends up with this plot:

 f[x_, y_] = x/(-x - 2 y)
StreamPlot[{1, f[x, y]}, {x, -10, 10}, {y, -10, 10}, Frame -> False,
Axes -> True, AspectRatio -> 1/GoldenRatio, StreamStyle -> "PinDart"] Unfortunately, streamlines are interrupting on line $y = -\dfrac{x}{2}$, when they should go as they were. By this, I mean that there should be only clockwise directed streamlines.

Is there any straightforward way to deal with this issue? Thank you!

• But are you sure this is not right? y=-x/2 is where the direction of tangent changes. Just plug in x=-1, y=1 above this line and x=-1 y=0 below this line, and you get the slope of +1 for the former case and -1 for the latter case. – MathX Mar 19 '16 at 0:38
• What is the ODE you're trying to plot the trajectories of? – user484 Mar 19 '16 at 1:34
• @Rahul This one: $y' = \dfrac{x}{-x-2y}$ – RuD_wow Mar 20 '16 at 13:44
• @RuD_wow: The denominator of that ODE cannot be $y = -\dfrac{x}{2}$, else the ODE is undefined. This is a line as shown in the phase portrait, so the phase portrait you show above is is correct. – Moo Mar 20 '16 at 14:22
• @Moo But, what if we will calculate the eigenvalues of system $\dfrac{dx}{dt}, \dfrac{dy}{dt}$ and, considering their Real values, make a conclusion that DE' s phase trajectories are logarithmic clockwise spiral? – RuD_wow Mar 21 '16 at 18:12

## 2 Answers

Will this do the trick:

Clear[f]
f[x_, y_] := {1, x/(-x - 2 y)};
f[x_, y_] /; y > -x/2 := -{1, x/(-x - 2 y)};
StreamPlot[f[x, y], {x, -10, 10}, {y, -10, 10}, Frame -> False,
Axes -> True, AspectRatio -> 1/GoldenRatio, StreamStyle -> "PinDart"]

• Thank you a lot! I was thining about the same tricky way, but stucked on how to implement it. – RuD_wow Mar 20 '16 at 14:26

Since we're not given an ODE by the OP, it's hard to comment on which phase portrait is correct. But taking the OP's desire for clockwise flow as given and working backwards, we might reach the following system (or a positive multiple of it): $${dx \over dt} = x+2y,\ {dy \over dt} = -x \,.\tag{1}$$ In that case, the phase field is given by

Clear[f]
f[x_, y_] := {x + 2 y, -x};

StreamPlot[f[x, y], {x, -10, 10}, {y, -10, 10}, Frame -> False,
Axes -> True, AspectRatio -> 1/GoldenRatio, StreamStyle -> "PinDart"] (If the ODE/system was $${d^2y\over dt^2} + {dy \over dt} + 2y=0$$, with $$x = dy/dt$$, then the flow as plotted would be the same as above, because the "position" y and the "velocity" x are switched from the usual velocity versus position. If the ODE/system was $$dy/dx = x/(-x-2y)$$, then $$dx/dt = 1 > 0$$ and all trajectories move to the right; the original stream plot was correct. And if the ODE/system was a negative multiple of (1), then the phase flow is counterclockwise.)