当我为 Y 维度选择某些函数值时,出现已知维度过大错误:
\begin{tikzpicture}[>=stealth]
\begin{axis}[
height=\textwidth,
width=\textwidth,
xmin=-1.05,xmax=1.05,
%ymin=0.002524,ymax=0.002525,
ymin=-1,ymax=1,
axis x line=middle,
axis y line=middle,
axis line style=<->,
xlabel={$x$},
ylabel={$y$},
xtick={-1,-0.5,0,0.5, 1},
scaled y ticks = false,
y tick label style={/pgf/number format/sci},
]
\addplot[no marks,blue,line width=1pt] expression[domain=-1:1,samples=200]{sqrt(1+x/5) - (0.997475+0.1 * x-0.00499923 *x^2+0.000499811 * x^3-0.0000645293 * x^4+9.12394*10^-6 * x^5)}
;
\end{axis}
\end{tikzpicture}
但我不明白为什么我在这个区间 y = [-1,1] 上收到维度过大错误……
当我将间隔更改为 y = [0.002524, 0.002525] 时,我得到了错误间隔的输出:
谁能指出我解决这个问题的正确方法?
答案1
PGF 数学引擎对于这些类型的范围不够精确。如果您改用gnuplot
进行计算(通过在代码中替换expression
)gnuplot
,您将获得正确的输出:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[>=stealth]
\begin{axis}[
height=\textwidth,
width=\textwidth,
axis lines=middle,
axis line style=<->,
xlabel={$x$},
ylabel={$y$},
xtick={-1,-0.5,0,0.5, 1},
scaled y ticks = false,
y tick label style={/pgf/number format/fixed, /pgf/number format/fixed zerofill, /pgf/number format/precision=8},
]
\addplot[no marks,blue,line width=1pt] gnuplot [domain=-1:1,samples=200]{sqrt(1+x/5) - (0.997475+0.1 * x-0.00499923 *x^2+0.000499811 * x^3-0.0000645293 * x^4+9.12394*10^-6 * x^5)}
;
\end{axis}
\end{tikzpicture}
\end{document}