I've cobbled together some code I've found to draw slope fields for my class. It does the job rather well, except for the following DE, and others, specifically, in this case: the resultant output clearly shows field lines with slope zero, which shouldn't be the case.
Any suggestions? I've appended the code:
\documentclass[border=5pt,tikz]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{gnuplottex}
\begin{document}
\begin{tikzpicture}
[declare function={f(\x,\y)=(3*(\x^2)+2)/(2*\y);},scale=2.0]
%limits
\def\xmax{3} \def\xmin{-3}
\def\ymax{3} \def\ymin{-3}
\def\nx{11}
\def\ny{11}
%slope field
\pgfmathsetmacro{\hx}{(\xmax-\xmin)/\nx}
\pgfmathsetmacro{\hy}{(\ymax-\ymin)/\ny}
\foreach \i in {0,...,\nx}
\foreach \j in {0,...,\ny}{
\pgfmathsetmacro{\yprime}{f({\xmin+\i*\hx},{\ymin+\j*\hy})}
\draw[blue,shift={({\xmin+\i*\hx},{\ymin+\j*\hy})}]
(0,0)--($(0,0)!1mm!(.1,.1*\yprime)$);
}
%axes
\draw[->] (\xmin-.5,0)--(\xmax+.5,0) node[below right] {{$x$}};
\draw[->] (0,\ymin-.5)--(0,\ymax+.5) node[above left] {{$y$}};
\draw (current bounding box.north) node[above]
%label
{Slope field of \quad $\displaystyle \frac{dy}{dx}=\frac{3x^2+2}{2y}$.};
\end{tikzpicture}
\end{document}

gnuplottexin this example? It is probably also a better idea to usepgfplotsas it will make all the axis for you automatically. Perhaps it even has a build in function to do what you are looking for. – daleif Aug 28 '19 at 13:58[declare function={f(\x,\y)=(3*\x*\x+2)/(2*\y);}since\x^2is not the square of\x, see https://tex.stackexchange.com/q/5400 or https://tex.stackexchange.com/q/469747. Rather, for negative\xthis is-abs(\x)^2, i.e. negative, which is why the "slope" can become zero. (I also have problems seeing how your axis description is correct. You have a functionf(\x,\y). You plot lines from a given(x,y)to(x+0.1,y+0.1*f(x,y). How are these the slope lines? Shouldn't you compute the gradient for that?) – Aug 28 '19 at 16:08