# Problems encountered in plotting direction fields

I learned how to plot direction fields according to the answer of @Robert Jacobson to the question How can I plot the direction field for a differential equation?. However, when I tried to plot the direction field for $$\dfrac{dy}{dx}=\dfrac{x}{y}$$, the direction field produced was wrong.

This is what I got:

The gradients at y = 0 are supposed to be infinity and there are supposed to be vertical red line segments on the x-axis. I cannot figure out why.

F[x_, y_] := x/y

VectorPlot[{1, F[x, y]}/Sqrt[1 + F[x, y]^2], {x, -3, 3}, {y, -3, 3},
VectorScale -> 0.025,
VectorPoints -> 13,
VectorStyle -> {"Segment", Red},
Frame -> None,
Axes -> True,
AxesStyle -> Directive[Black, 15.5, FontFamily -> "Times",
AxesLabel -> {x, y},
Ticks ->
{{-3, {-2.5, ""}, -2, {-1.5, ""}, -1, {-0.5, ""}, 0,
{0.5, ""}, 1, {1.5, ""}, 2, {2.5, ""}, 3},
{-3, {-2.5, ""}, -2, {-1.5, ""}, -1, {-0.5, ""}, 0,
{0.5, ""}, 1, {1.5, ""}, 2, {2.5, ""}, 3}}]

• If you change your intervals to, say, {x,-1,1} and {y,-1,1}, or even smaller, the vectors on the x-axis will look more vertical. At the origin, now that's a problem. The reason you don't see it with your scales may be that the vectors are not the gradient at exactly the x-axis. – LouisB Apr 30 at 8:10
• @LouisB Thanks. But why changing to a smaller interval makes vectors more vertical? – Siwei Apr 30 at 8:14
• Because this is a problem of division of your interval. The plot has a finite number of points and generally they are not coinciding with y=0. Try to play with increasing PlotPoints putting the odd numbers. – Rom38 Apr 30 at 8:29

Maybe special-case the singular results:

F[x_, y_] := x/y;
vf[Indeterminate] := {0., 0.};
vf[ComplexInfinity | Infinity | -Infinity] := {0., 1.};
vf[m_] := {1, m}/Sqrt[1 + m^2];
VectorPlot[vf[F[x, y]], {x, -3, 3}, {y, -3, 3}, VectorScale -> 0.025,
VectorPoints -> 13, VectorStyle -> {"Segment", Red}, Frame -> None,
Axes -> True,
AxesStyle ->
Directive[Black, 15.5, FontFamily -> "Times", AxesLabel -> {x, y},