0

I am trying to generate the slope field of dy/dx = (x-1)*(y+2)/3 to illustrate that along the lines x=1 and y=-2, the slope of the solutions curve is zero, indicated by horizontal lineal elements. However, the points being used to generate the arrow appear not to be exactly points along those lines, so the lineal elements are not appearing as horizontal. How can I adjust the setting to ensure the points being sample are using x=1 and y=-2?

\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
    Consider the following slope field. \par\bigskip
            \begin{center}
                \def\length{sqrt(1+((x-1)*(y+2)/3)^2)}
                \begin{tikzpicture}[>=stealth,x=1.5cm,y=1.5cm,scale=1.85,font=\footnotesize]
                    \begin{axis}[
                        axis lines=middle,
                        view={0}{90},
                        domain=-3:3,
                        xmin=-3.5,
                        xmax=3.5,
                        ymin=-3.5,
                        ymax=3.5,
                        samples=18,
                        axis equal image,
                        ticklabel style = {font=\tiny},
                        xtick={-3,-2,...,3},
                        ytick={-3,-2,...,3}
                        ]
                        \addplot3 [lightgray, quiver={u={1/(\length)}, v={((x-1)*(y+2)/3)/(\length)}, scale arrows=0.2, every arrow/.append style={-stealth}}] (x,y,0);
                    \end{axis}
                \end{tikzpicture}
            \end{center}
\end{document}
1

I think the problem is that you added a samples key. If you comment it, it should work properly. Just in case, I force X to have the value of -1 by using samples at key.

Just in case I misunderstood what you wanted, the resulting image is as follows, with the "linear" arrowsd at x=1. Is that correct?

enter image description here

And the MWE:

\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
    Consider the following slope field. \par\bigskip
            \begin{center}
                \def\length{sqrt(1+((x-1)*(y+2)/3)^2)}
                \begin{tikzpicture}[>=stealth,x=1.5cm,y=1.5cm,scale=1.85,font=\footnotesize]
                    \begin{axis}[
                        axis lines=middle,
                        view={0}{90},
                        domain=-3:3,
                        samples at={-3,-2.5,...,3}, <--- (!)
                        xmin=-3.5,
                        xmax=3.5,
                        ymin=-3.5,
                        ymax=3.5,
                        %samples=18,
                        axis equal image,
                        ticklabel style = {font=\tiny},
                        xtick={-3,-2,...,3},
                        ytick={-3,-2,...,3}
                        ]
                        \addplot3 [lightgray, quiver={u={1/(\length)}, v={((x-1)*(y+2)/3)/(\length)}, scale arrows=0.2, every arrow/.append style={-stealth}}] (x,y,0);
                    \end{axis}
                \end{tikzpicture}
            \end{center}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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