I am adapting the solution here to plot the slope field for a differential equation. The equation I would like to use is dy/dt = -sqrt(1-y^2). I can get it working for "simple" functions (see MWE) but not for this function that I want. You can see the various functions I have tried (commented out) in the MWE. For those cases that fail, I see
! Missing number, treated as zero.
<to be read again>
n
l.42 \end{axis}
I suspect the answer here regarding curly braces is related, but I have not managed to get this working for my problem.
MWE:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\pgfplotsset{
SlopeFieldAxis/.style={
axis equal image,
view={0}{90},
samples=11,
}
}
\begin{document}
\begin{tikzpicture}[
declare function={
f1(\x,\y) = 1.0 - \y*\y;
f2(\x,\y) = sqrt(\y);
f3(\x,\y) = -sqrt(f1(\x,\y));
f4(\x,\y) = -sqrt(1.0 - \y*\y);
}
]
\begin{axis}[
SlopeFieldAxis,
width=0.95\textwidth,
xmin=0, xmax=3.14159,
ymin=0, ymax=2.0,
zmin=0, zmax=1.0,
domain=0:3.14159, y domain=0:2,
]
\addplot3[
blue,
quiver={
u={1},
% v={f1(x,y)}, % works
% v={f2(x,y)}, % works
v={f3(x,y)}, % error
% v={f4(x,y)}, % error
scale arrows=0.075,
every arrow/.append style={-latex},
}
] (x,y,0);
\end{axis}
\end{tikzpicture}
\end{document}
f3(\x,\y) = -sqrt(f(\x,\y));. Itis not defined ... – Zarko Oct 09 '20 at 05:16y domain=0:0.5. – Torbjørn T. Oct 09 '20 at 14:38