在 TikZ 中绘制具有非常小值的函数

在 TikZ 中绘制具有非常小值的函数

我想在 TikZ 中绘制一个函数,G4这张纸(p5)。我尝试过使用和不使用 pgfplots,也尝试过 gnuplot 调用。MWE 如下。

使用pgfplots,编译会抛出错误! Dimension too large. <recently read> \pgf@yy l.54 \end{axis} ,而仅使用 TikZ 的尝试则会绘制 f(x) = 0。

该函数应如下所示 Behler 函数

此函数涉及一个小数乘以其他小数的指数。我怀疑提高计算精度就足以解决这个问题。我见过一些例子,precision=<number>但我不知道如何对绘制的函数而不是要打印的数字进行此操作。

这个答案显示了一个 gnuplot 调用,用于绘制一个 y 轴非常小的图,但我不想依赖外部程序。另外,我不知道我的宏依赖函数定义是否与 gnuplot 兼容。现在我尝试将宏更改为显式数字,但再次出现错误,! Dimension too large. <recently read> \pgf@yy l.43 \end{axis}

有办法解决这个问题吗?我完全不知道。

MWE(仅限 TikZ):

\documentclass[tikz]{standalone}

\usepackage{siunitx}

\begin{document}

\colorlet{colorline1}{red}

\def\xmax{360}
\def\ymax{0.02}

\tikzset{every picture/.style={x = 0.025cm,y = 60cm}}

\begin{tikzpicture}
\draw[->] (0,0) -- (0,\ymax) node [left] {\small $G_i^{4,5}$};
\draw[->] (0,0) -- (\xmax,0) node [below] {\small $\theta_{ijk}$/\si{\degree}};

\node[left] at (0,0) {\small $0$};

\def\coefValT{0.8}

% Cutoff function fc of Rij and Rik, with both distances fixed at 0.8*Rc
\pgfmathsetmacro{\fcOfijNikValT}{0.5*cos( \coefValT * pi r) + 0.5}

\def\lambdaVal{1}
\def\etaVal{0.2}
\def\zetaVal{1}

\def\Rc{10}
\pgfmathsetmacro{\RijNikValT}{\coefValT*\Rc}

% Function to plot begins here
\begin{scope}[thick,colorline1]
\def\fcOfijNik{\fcOfijNikValT}
\draw[domain=0:\xmax,variable=\x,samples=100,smooth] plot (\x,{2^(1-\zetaVal)*(1 + \lambdaVal*cos(\x))^\zetaVal*exp( -\etaVal*( 2*(\RijNikValT)^2 +
% Calculation for Rjk^2:
2*(\RijNikValT)^2 - 2*(\RijNikValT)^2*cos(\x)
))* % these two parenthesis close the one opened by \etaVal*, and by exp(
\fcOfijNik^2*(
% Calculation for fc(Rjk)
0.5*(cos( pi*
% Calculation for Rjk:
(%opens quotient multiplied by pi
sqrt( 2*(\RijNikValT)^2 - 2*(\RijNikValT)^2*cos(\x) )
/\Rc)%ends quotient multiplied by pi
)% closes parenth opened by cos
)% closes parenth opened to the left of cos
+0.5)%closes parenth opened before of 0.5*(cos
});
\end{scope}
\end{tikzpicture}
\end{document}

MWE(TikZ + pgfplots):

\documentclass[tikz]{standalone}

\usepackage{pgfplots}

\usepackage{siunitx}

\begin{document}

\colorlet{colorline1}{red}

\def\xmax{360}
\def\ymax{0.02}

\tikzset{every picture/.style={x = 0.025cm,y = 60cm}}

\begin{tikzpicture}
\draw[->] (0,0) -- (0,\ymax) node [left] {\small $G_i^{4,5}$};
\draw[->] (0,0) -- (\xmax,0) node [below] {\small $\theta_{ijk}$/\si{\degree}};

\node[left] at (0,0) {\small $0$};

\def\coefValT{0.8}

% Cutoff function fc of Rij and Rik, with both distances fixed at 0.8*Rc
\pgfmathsetmacro{\fcOfijNikValT}{0.5*cos( \coefValT * pi r) + 0.5}

\def\lambdaVal{1}
\def\etaVal{0.2}
\def\zetaVal{1}

\def\Rc{10}
\pgfmathsetmacro{\RijNikValT}{\coefValT*\Rc}

%\begin{axis}[range=0:360,restrict y to domain=0:0.02]
\begin{axis}[xmin=0, xmax = 360,ymin = 0, ymax = 0.02]
% Function to plot begins here
\begin{scope}[thick,colorline1]
\def\fcOfijNik{\fcOfijNikValT}
\addplot {2^(1-\zetaVal)*(1 + \lambdaVal*cos(\x))^\zetaVal*exp( -\etaVal*( 2*(\RijNikValT)^2 +
% Calculation for Rjk^2:
2*(\RijNikValT)^2 - 2*(\RijNikValT)^2*cos(\x)
))* % these two parenthesis close the one opened by \etaVal*, and by exp(
\fcOfijNik^2*(
% Calculation for fc(Rjk)
0.5*(cos( pi*(
% Calculation for Rjk:
sqrt( 2*(\RijNikValT)^2 - 2*(\RijNikValT)^2*cos(\x) )
/\Rc)%ends quotient multiplied by pi
)% closes parenth opened by cos
)% closes parenth opened to the left of cos
+0.5)%closes parenth opened before of 0.5*(cos
};
\end{scope}
\end{axis}

\end{tikzpicture}
\end{document}

MWE(TikZ + pgfplots + gnuplot):

\documentclass[tikz]{standalone}

\usepackage{pgfplots}

\usepackage{siunitx}

\begin{document}

\colorlet{colorline1}{red}

\def\xmax{360}
\def\ymax{0.02}

\tikzset{every picture/.style={x = 0.025cm,y = 60cm}}

\begin{tikzpicture}
\draw[->] (0,0) -- (0,\ymax) node [left] {\small $G_i^{4,5}$};
\draw[->] (0,0) -- (\xmax,0) node [below] {\small $\theta_{ijk}$/\si{\degree}};

\node[left] at (0,0) {\small $0$};

%\begin{axis}[range=0:360,restrict y to domain=0:0.02]
\begin{axis}[xmin=0, xmax = 360,ymin = 0, ymax = 0.02]
% Function to plot begins here
\begin{scope}[thick,colorline1]
\def\fcOfijNik{\fcOfijNikValT}

\addplot[no marks,blue,line width=1pt] gnuplot [domain=0:360,samples=200] {2^(1-1)*(1 + 1*cos(x))^1.1*exp( -0.2*( 2*(8)^2 +
% Calculation for Rjk^2:
2*(8)^2 - 2*(8)^2*cos(x)
))* % these two parenthesis close the one opened by \etaVal*, and by exp(
8^2*(
% Calculation for fc(Rjk)
0.5*(cos( pi*(
% Calculation for Rjk:
sqrt( 2*(8)^2 - 2*(8)^2*cos(x) )
/10)%ends quotient multiplied by pi
)% closes parenth opened by cos
)% closes parenth opened to the left of cos
+0.5)%closes parenth opened before of 0.5*(cos
};
\end{scope}
\end{axis}

\end{tikzpicture}
\end{document}

答案1

只是为了确认hpekristiansen 的评论pgfplots确实有效。但是,首先你需要消除

\tikzset{every picture/.style={x = 0.025cm,y = 60cm}}

以及

\draw[->] (0,0) -- (0,\ymax) node [left] {\small $G_i^{4,5}$};
\draw[->] (0,0) -- (\xmax,0) node [below] {\small $\theta_{ijk}$/\si{\degree}};

分别变为ylabelxlabel。此后,您的代码就可以正常工作了。

\documentclass[tikz]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=1.17} 
\usepackage{siunitx}

\begin{document}

\colorlet{colorline1}{red}

\def\xmax{360}
\def\ymax{0.02}

%\tikzset{every picture/.style={x = 0.025cm,y = 60cm}}

\begin{tikzpicture}
% \draw[->] (0,0) -- (0,\ymax) node [left] {\small $G_i^{4,5}$};
% \draw[->] (0,0) -- (\xmax,0) node [below] {\small $\theta_{ijk}$/\si{\degree}};
% 
% \node[left] at (0,0) {\small $0$};

\def\coefValT{0.8}

% Cutoff function fc of Rij and Rik, with both distances fixed at 0.8*Rc
\pgfmathsetmacro{\fcOfijNikValT}{0.5*cos( \coefValT * pi r) + 0.5}

\def\lambdaVal{1}
\def\etaVal{0.2}
\def\zetaVal{1}

\def\Rc{10}
\pgfmathsetmacro{\RijNikValT}{\coefValT*\Rc}

%\begin{axis}[range=0:360,restrict y to domain=0:0.02]
\begin{axis}[xmin=0, xmax = 360,ymin = 0,
    ylabel={\small $G_i^{4,5}$},xlabel={\small $\theta_{ijk}$/\si{\degree}}]
% Function to plot begins here
\begin{scope}[thick,colorline1]
\def\fcOfijNik{\fcOfijNikValT}
\addplot[domain=0:360,samples=201] 
{2^(1-\zetaVal)*(1 + \lambdaVal*cos(\x))^\zetaVal*exp( -\etaVal*( 2*(\RijNikValT)^2 +
% Calculation for Rjk^2:
2*(\RijNikValT)^2 - 2*(\RijNikValT)^2*cos(\x)
))* % these two parenthesis close the one opened by \etaVal*, and by exp(
\fcOfijNik^2*(
% Calculation for fc(Rjk)
0.5*(cos( pi*(
% Calculation for Rjk:
sqrt( 2*(\RijNikValT)^2 - 2*(\RijNikValT)^2*cos(\x) )
/\Rc)%ends quotient multiplied by pi
)% closes parenth opened by cos
)% closes parenth opened to the left of cos
+0.5)%closes parenth opened before of 0.5*(cos
};
\end{scope}
\end{axis}

\end{tikzpicture}
\end{document}

在此处输入图片描述

这仍然是一个非常生疏的代码,并且规范化与您的预期不同,但这只是为了证实它在原则上有效。

如果您想要更清晰的代码,那么您可能首先需要重新措辞该问题,以便其他人更好地了解正在发生的事情。

相关内容