给定 y 值,在函数的两个交点之间画线(莫尔斯势)

给定 y 值,在函数的两个交点之间画线(莫尔斯势)

我必须在莫尔斯势曲线中画出线(振动能量线)。

让我用一个更一般的例子来解释:

如果我有一个抛物线 x²,我想根据一组 y 值在其中绘制线条,例如 (1; 0.5; 0.7; 0.8; 0.85; 0.875)。我怎样才能绘制这些线直到交点?例如,我怎样才能找到 x 值来绘制从 (-1,1) 到 (1,1) 的第一条线?

我的目的是画一个像这样的图形

莫尔斯势

答案1

更新

方法一:使用intersections

这是一种用于pgfplots绘制实际莫尔斯势的方法。它用于\pgfmathdeclarefunction定义一个势函数V和另一个计算第 n 个束缚态能量的函数,然后使用该tikzintersections计算此高度未绘制的水平线与莫尔斯势的交点。最后,它从一个交点到下一个交点绘制水平线。参见pgfplots:在 pgfplotsextra 中使用 foreach 创建的路径名有关在 内命名路径的信息pgfplotsinvokeforeach

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{intersections}

\begin{document}

%%%%%%% Define Potential Function %%%%%%%
\pgfmathsetmacro{\De}{10}
\pgfmathsetmacro{\re}{1}
\pgfmathsetmacro{\a}{1}
\pgfmathdeclarefunction{V}{1}{%
  \pgfmathparse{%
    \De*((1-exp(-\a*(#1-\re)))^2-1)
    }%
}
%%%%%%% Energy Levels %%%%%%%
% energies are given as multiples of \hbar \omega_0 with
% \omega_0 = \a*sqrt(2*\De/\m), where m is the (reduced) mass of the diatomic molecule
% \De above is really \De/(\hbar*\omega)
\pgfmathdeclarefunction{energy}{1}{%
  \pgfmathparse{%
    -\De+(#1+0.5) - (#1+0.5)^2/(4*\De)
    }%
}

\begin{tikzpicture}
\begin{axis}[axis lines = middle,smooth,xlabel = $r/r_e$, ylabel =$E/\hbar \omega_0$, minor tick num =1, grid=none, no markers, every axis x label/.style={ at={(ticklabel* cs:1.05)}, anchor=west},
every axis y label/.style={at={(ticklabel* cs:1.05)},anchor=south},domain=0:10, enlargelimits = true,scale=1.5]
\addplot +[thick, samples=50, name path global=MorseCurve] {V(x)};
\pgfplotsinvokeforeach{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17}{
    \path [name path global=HelperLine-#1] (axis cs: 0,{energy(#1)}) -- (axis cs: 10, {energy(#1)});
    \draw[name intersections={of=MorseCurve and HelperLine-#1}] (intersection-1) -- (intersection-2);
}

\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

方法 2:交点解析形式

使用交点的解析形式,计算起来相当容易。这是我的原始帖子,只是我将\edefs改为pgfplotsinvokeforeach

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}

%%%%%%% Define Potential Function %%%%%%%
\pgfmathsetmacro{\De}{10}
\pgfmathsetmacro{\re}{1}
\pgfmathsetmacro{\a}{1}
\pgfmathdeclarefunction{V}{1}{%
  \pgfmathparse{%
    \De*((1-exp(-\a*(#1-\re)))^2-1)
    }%
}
%%%%%%% Energy Levels %%%%%%%
% energies are given as multiples of \hbar \omega_0 with
% \omega_0 = \a*sqrt(2*\De/\m), where m is the (reduced) mass of the diatomic molecule
% \De above is really \De/(\hbar*\omega)
\pgfmathdeclarefunction{energy}{1}{%
  \pgfmathparse{%
    -\De+(#1+0.5) - (#1+0.5)^2/(4*\De)
    }%
}
%Upper limit on classical bound state of a given energy
\pgfmathdeclarefunction{rmax}{1}{%
  \pgfmathparse{%
    (\a*\re+ln( - (\De+sqrt(\De*(#1+\De)))/#1 ) )/\a
    }%
}
%Lower limit on classical bound state of a given energy
\pgfmathdeclarefunction{rmin}{1}{%
  \pgfmathparse{%
    (\a*\re+ln( (-\De+sqrt(\De*(#1+\De)))/#1 ) )/\a
    }%
}


\begin{tikzpicture}
\begin{axis}[axis lines = middle,smooth,xlabel = $r/r_e$, ylabel =$E/\hbar \omega_0$, minor tick num =1, grid=none, no markers, every axis x label/.style={ at={(ticklabel* cs:1.05)}, anchor=west},
every axis y label/.style={at={(ticklabel* cs:1.05)},anchor=south},domain=0:10, enlargelimits = true,scale=1.5]
% \foreach inside axis environment was tricky, see https://tex.stackexchange.com/questions/17638/pgfplots-foreach-equivalent-to-tikzs-with-multiple-variables-separated-by-a-sla/17817#17817
\pgfplotsinvokeforeach{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17}{
    \draw (axis cs: {rmin( energy(#1) )},{energy(#1)}) -- (axis cs: {rmax(energy(#1))},{energy(#1)});
}
\addplot +[thick, samples=50] {V(x)};
\node[style ={ align=center}] at (axis cs: 7,14) {Morse potential: \\ $V(r) = D_e \left( [1-e^{-a(r-r_e)}]^2-1 \right)$ };
\node[style ={ align=center}] at (axis cs: 7,7) {Energy levels: \\ $E_n = -D_e + \hbar \omega_0 (n+1/2) + \frac{[\hbar \omega_0 (n+1/2)]^2}{4 D_e} $ \\ with $\omega_0 = a \sqrt{2 D_e/m}$ };
\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

使用 TikZ,不绘制显式 Morse 势,并进行裁剪。(上面的蓝色曲线实际上不是激发态,而是一条看起来很相似的曲线)

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
    \draw[->] (-0.3,0) -- node[sloped,below] {Bond length} (6,0);
    \draw[->] (0,-0.3) -- node[sloped,above] {Enery wavenumbers} (0,5);
    \begin{scope}
        \draw[blue,thick] plot[smooth,domain=0.5:2.5] (\x,{0.2*exp(-20*(\x-1.5)^2)+1)});
        \coordinate (a) at (1.2,1);
        \draw[clip] plot[smooth,tension=0.7] coordinates {(0.5,4) (1,0.1) (3,1.5) (5,2)};
        \foreach \i in {1,2,3,...,6} {
            \draw (0,{2-2/(2*\i)}) -- (5,{2-2/(2*\i)});
        }
    \end{scope}
    \begin{scope}[shift={(0.5,2.5)}]
        \draw[blue,thick] plot[smooth,domain=0.5:2.5] (\x,{0.4*cos(5.5*pi*(\x-1.5) r)^2*sin((\x-1.5) r)^2+1.5});
        \coordinate (b) at (0.7,1.5);
        \path[clip] (0,0) rectangle (5,2);
        \draw[clip] plot[smooth,tension=0.7] coordinates {(0.5,4) (1,0.1) (3,1.5) (5,2)};
        \foreach \i in {1,2,3,...,6} {
            \draw (0,{2-2/(2*\i)}) -- (5,{2-2/(2*\i)});
        }
    \end{scope}
    \draw[red,->] (a) -- (b);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

使用 PSTricks。

\documentclass[pstricks,border=12pt]{standalone}

\usepackage{pst-plot}
\psset
{
    algebraic,
    plotpoints=100,
}

\def\f{(x+1)*(x-2)*(x-2.5)-1}

\begin{document}
\begin{pspicture}(-1,-2)(5,6)
    \psaxes[linecolor=gray,ticksize=4pt 0]{->}(0,0)(-1,-4)(4.5,5.5)[$x$,0][$y$,90]
    \begin{psclip}
    {
        \pscustom[linestyle=none]
        {
            \psplot{-1}{3.4}{\f}
            \psline(-1,0|*3.4 {\f})
            \closepath
        }
    }
        \foreach \y in {.5,.7,.8,1,2,3}{\psline(0,\y)(4.5,\y)}% important percent sign 
    \end{psclip}
    \psplot[linecolor=blue]{-1}{3.4}{\f}
\end{pspicture}
\end{document}

在此处输入图片描述

相关内容