
我正在嘗試使用 pgfplot 繪製滴定曲線。基於這張紙,滴定曲線有方程式:
我嘗試在 pgfplots 中實現這一點,但得到了一個非常奇怪的結果:
我不知道為什麼會發生這種情況;甚至嘗試重新創建我在其中使用的確切公式鎖骨不工作。
作為參考,這裡是程式碼,還有一個連結到背頁項目。
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\pgfkeys{
/pgf/declare function={
arcsinh(\x) = ln(\x + sqrt(\x^2+1));
},
/pgf/declare function={
Va = 0.025;
Ma = 0.1;
Mb = 0.1;
V(\x) = \x / 1000;
Kw = 1*10^(-14);
p(\o) = -ln(\o)/ln(10);
}
}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xlabel = {Solution Added (mL)},
ylabel = {pH},
ymin=0,
ymax=14,
ytick distance=7,
xtick distance=10,
]
\addplot[%
samples=100,
color=red,
domain=0:50,
]{%
7 + 1/ln(10) * arcsinh( 1/(2*sqrt(Kw)) * (Mb*V(x) - Ma*Va) / (Va + V(x)) )
};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
尾註:如果有一種方法可以在 pgfplot 函數中使用變量,例如 V_a,那會比始終使用常數要好得多。謝謝托洪
答案1
人們得到這個奇怪的結果是因為達到了 TeX 的限制——這也可以從下降的座標中看出——因此「之字形」是由精度限制(紅線)產生的。如果您使用 gnuplot(綠點)或 Lua(藍線)作為計算引擎,它會按預期工作。當然,對於 Lua 解決方案,您必須使用 LuaLaTeX 作為 TeX 引擎。
邊註:
如果您想避免使用如此多的樣本,請考慮重新制定方程式以利用非線性間距。為此,請參閱例如
% used PGFPlots v1.17
\documentclass[border={5pt}]{standalone}
\usepackage{pgfplots}
% use this `compat` level or higher to use LUA backend for calculation (if possible)
\pgfplotsset{compat=1.12}
\begin{document}
% for gnuplot solution
\newcommand*{\Kw}{1e-14}
\newcommand*{\Ma}{0.1}
\newcommand*{\Mb}{0.1}
\newcommand*{\Va}{0.025}
\begin{tikzpicture}[
% from https://tex.stackexchange.com/q/144778
/pgf/declare function={
% for LUA solution
arcsinh(\x) = ln(\x + sqrt(\x^2+1));
Kw = 1e-14;
Ma = 0.1;
Mb = 0.1;
Va = 0.025;
V(\x) = \x / 1000;
p(\o) = -0.5*ln(\o)/ln(10);
},
]
\begin{axis}[
xlabel={Solution Added (mL)},
ylabel={pH},
domain=0:50,
samples=201,
]
% gnuplot
\addplot+ [ultra thick,green,mark size=1pt,only marks,opacity=0.5] gnuplot
{-0.5*log10(\Kw) + asinh(1/(2*sqrt(\Kw)) * (\Ma*\Va - \Mb*x/1000)/(\Va + x/1000) )/log(10)};
% Lua(TeX)
\addplot [thick,blue]
{p(Kw) + arcsinh(1/(2*sqrt(Kw)) * (Ma*Va - Mb*V(x))/(Va + V(x)) )/ln(10)};
% TeX
\addplot [red,opacity=0.75]
{p(\Kw) + arcsinh(1/(2*sqrt(Kw)) * (Ma*Va - Mb*V(x))/(Va + V(x)) )/ln(10)};
\end{axis}
\end{tikzpicture}
\end{document}