I'm trying to plot a slope field of the function 2x/y using pgfplots such that the length of each quiver is fixed. The code is below
\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
declare function={
f(\x,\y) = (\y != 0) * (2\x/\y);
length(\x,\y) = sqrt(1+(2\x/\y)^2);
result = (6 +0.5)/14;
},
domain=-0.5:6,
view={0}{90},
axis lines=center
]
\addplot3[blue, quiver={u={1/length(x,y)}, v={f(x,y)/length(x,y)}, scale arrows=result}, -stealth, samples=14] {0};
\end{axis}
\end{tikzpicture}% Extra \else. ...e arrows=result}, -stealth, samples=14] {0};
\end{document}
Here I define my functions and try to use them in the quiver plot. However, I get the following unhelpful error
! Extra \else.
\pgfmath@local@next ...@local@function@body \else
\if #1(\let \pgfmath@local...
l.32 ...e arrows=length}, -stealth, samples=14] {0};
I can't see what's wrong with the code. I have tried, without success
- Changing the
/=sign into other possible alternatives, such as!=, - Plugging in the function calls with their literals
Can I please have some help with this?

;at the end of theresultdefinition. Aside from that, what is/=supposed to represent? The "not equal" comparison operator is!=. – Torbjørn T. Dec 09 '21 at 16:28Package PGF Math Error: Could not parse input 'result' as a floating point number, sorry. The unreadable part was near 'result'.. ...e arrows=result}, -stealth, samples=14] {0};– Kookie Dec 09 '21 at 17:09