尝试使用 erf 函数绘制 BER 与 SNR 函数。但是我收到一条错误消息,提示“Package PGF Math Error: Could not parse input '' as a floating point number, sorry. The unreadable part was near ''. (in '0.5-0.5*erf(sqrt(10**(x/10)))')”
\documentclass[convert={density=400,outext=.png}]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{
label style={anchor=near ticklabel},
xlabel style={yshift=0.8em},
ylabel style={yshift=-2em},
tick label style={font=\bfseries\small },
label style={font=\bfseries\small},
legend style={font=\bfseries\small},
}
\begin{document}
\begin{tikzpicture}[
declare function={erf(\x)=%
(1+(e^(-(\x*\x))*(-265.057+abs(\x)*(-135.065+abs(\x)%
*(-59.646+(-6.84727-0.777889*abs(\x))*abs(\x)))))%
/(3.05259+abs(\x))^5)*(\x>0?1:-1);},
declare function={erf2(\x,\y)=erf(\x)+erf(\y);}
]
\begin{axis}[xdomain:0:30,
width=\textwidth,
enlargelimits=false,
grid=major,
]
\addplot {0.5-0.5*erf(sqrt(10**(x/10)))};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您的代码中有几处需要更改:
10^
不使用10**
exp(...)
不使用e^(...)
domain=...
不使用xdomain=...
这是一个完整的 MWE - 记住从小处着手,慢慢积累:)当您遇到错误时,研究消息,注释掉代码片段,并不断调整直到修复它。
% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
label style={anchor=near ticklabel},
xlabel style={yshift=0.8em},
ylabel style={yshift=-2em},
tick label style={font=\bfseries\small },
label style={font=\bfseries\small},
legend style={font=\bfseries\small},
}
\begin{document}
\begin{tikzpicture}[
/pgf/declare function={erf(\x)=%
(1+(exp(-(\x*\x))*(-265.057+abs(\x)*(-135.065+abs(\x)%
*(-59.646+(-6.84727-0.777889*abs(\x))*abs(\x)))))%
/(3.05259+abs(\x))^5)*(\x>0?1:-1);},
]
\begin{axis}[domain=0:30,
width=\textwidth,
enlargelimits=false,
grid=major,
]
\addplot {0.5-0.5*erf(sqrt(10^(x/10)))};
\end{axis}
\end{tikzpicture}
\end{document}