我对 y 值的计算有疑问pgfplots
。
在我的 MWE 中,这些值的计算似乎存在问题。
\documentclass[border=5pt,tikz]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepgfplotslibrary{fillbetween}
\usepgfplotslibrary{colormaps}
\pgfplotsset{compat=newest}
\pgfplotsset{every tick label/.append style={font=\small}}
\pgfplotsset{every axis label/.append style={font=\large}}
\pgfplotsset{every axis/.append style={line width=0.5pt}}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\begin{document}
\def\height{16cm}
\def\width{16cm}
\def\sc{0.8}
\def\xmin{2}
\def\xmax{5}
\def\ymin{0}
\def\ymax{30000}
\def\enlarge{0.05}
\def\Gda{12244}
\def\Gdb{4773.48}
\def\Gdc{1861} % Gdb/Gda*Gdb
\def\Gpa{15526.95}
\def\Gpb{6053.38} % Gdb/Gda*Gpb
\def\aa{1.87}
\def\ab{1.76}
\def\ac{1.66} % ab/aa*ab
\def\reqa{2.67}
\def\reqb{2.97}
\def\reqc{3.30} % reqb/reqa*reqb
\def\va{216.92}
\def\vb{125.20}
\def\vc{72.26} % vb/va*vb
\def\xva{2.07}
\def\xvb{0.82}
\def\xvc{0.33} % xvb/xva*xvb
\def\f{1}
\begin{tikzpicture}
\definecolor{darkorange}{RGB}{255,140,0}
\definecolor{darkblue}{RGB}{0,0,139}
\begin{axis}[
height=\height,
width=\width,
scale only axis=true,
scale=\sc,
enlarge x limits=\enlarge,
enlarge y limits=\enlarge,
xmin=\xmin,
xmax=\xmax,
ymin=\ymin,
ymax=\ymax,
restrict x to domain=\xmin:\xmax,
restrict y to domain=\ymin:\ymax,
samples=100,
xlabel=$\mathrm{\p}$, %<- here, I added the result of the calculation for comparison
ylabel=$\mathrm{V(r)}$,
]
\addplot[
name path global=A,
color=black,
smooth,
]
(x,{\Gda*(1-exp(-\aa*(x-\reqa)))^2});
\addplot[
name path global=B,
color=black,
smooth,
]
(x,{\Gpa+\Gdb*(1-exp(-\ab*(x-\reqb)))^2});
\addplot[
name path global=C,
color=black,
smooth,
]
(x,{\Gpa+\Gpb+\Gdc*(1-exp(-\ac*(x-\reqc)))^2});
\foreach [evaluate=\i as \n using {\va*(\i+0.5)-\xva*(\i+0.5)^2}] \i in {0,1,...,40} {% <- here, I calculate all y-values till 40
\edef\temp{%
\noexpand \path[name path=AA-\i] (axis cs:\xmin,\n) -- (axis cs:\xmax,\n);
\noexpand \path[name intersections={of=A and AA-\i},];
\noexpand \coordinate (A1-\i) at (intersection-1);
\noexpand \coordinate (B1-\i) at (intersection-2);
\noexpand \draw[line width=0.125pt] (A1-\i) -- (B1-\i);
}\temp
}
\pgfmathsetmacro{\o}{\va*(40+0.5)-\xva*(40+0.5)^2} %<- here, as comparison, I calculated the value for 40
\path[name path=AA40] (axis cs:\xmin,\o) -- (axis cs:\xmax,\o);
\path[name intersections={of=A and AA40}];
\coordinate (A40) at (intersection-1);
\coordinate (B40) at (intersection-2);
\draw[darkorange, line width=0.125pt] (A40) -- (B40);
\pgfmathsetmacro{\p}{\Gpa+\vb*(20+0.5)-\xvb*(20+0.5)^2} %<- the correct value should be 17748.95, but the system gives me 16039.39
\path[name path=BB20] (axis cs:\xmin,\p) -- (axis cs:\xmax,\p);
\path[name intersections={of=B and BB20}];
\coordinate (A20) at (intersection-1);
\coordinate (B20) at (intersection-2);
\draw[darkorange, line width=0.125pt] (A20) -- (B20);
\end{axis}
\end{tikzpicture}
\end{document}
问题应该出在\Gpa+
参数上,因为没有这个参数的计算也是正确的。
我运行 MWE 时遇到的错误是Dimension too large. ...ro{\p}{\Gpa+\vb*(20+0.5)-\xvb*(20+0.5)^2}
答案1
pgf 数学引擎执行的所有计算在任何时候都不得超过 ±16383.99999。因此,解决方法可能是将所有 y 值除以 10^4 或 10^3,并相应地设置图的 y 标签。