tan 与 pgfplots 中的表达式的交点

tan 与 pgfplots 中的表达式的交点

我正在尝试找到使用 addplots 绘制的两个图形之间的交点

\begin{tikzpicture}
\begin{axis}[
width=0.75\textwidth,
height=0.5\textwidth,
xmin=0, xmax=29000,
ymin=-10,ymax=10,
xlabel={$k$},
xlabel near ticks,
ylabel near ticks,
restrict y to domain=-11:11,
restrict x to domain=0:24000,
samples=1000,
axis x line=center,
axis y line=left,
scaled ticks=false, tick label style={/pgf/number format/fixed,
      /pgf/number format/1000 sep = \thinspace }
]

\def\nf{1.50}
\def\ns{1.45}
\def\nc{1.40}
\def\d{0.0005}
\def\lamda{0.0001}
\def\k{2*pi/\lamda}

\addplot[name path global=Aymm] gnuplot [domain=1:25000]{
 ((sqrt((sqrt(((2*pi/\lamda)^(2)*\nf^(2))-x^(2)))^(2)-((2*pi/\lamda)^(2)*\ns^(2))))+(sqrt((sqrt(((2*pi/\lamda)^(2)*\nf^(2))-x^(2)))^(2)-((2*pi/\lamda)^(2)*\nc^(2)))))/((x-(sqrt((sqrt(((2*pi/\lamda)^(2)*\nf^(2))-x^(2)))^(2)-((2*pi/\lamda)^(2)*\ns^(2)))*(sqrt((sqrt(((2*pi/\lamda)^(2)*\nf^(2))-x^(2)))^(2)-((2*pi/\lamda)^(2)*\nc^(2))))/x)))
     };

\addplot[magenta, name path global=Symm] gnuplot [domain=1:25000]{ tan(\d*x)};

\draw[name intersections={of=Aymm and Symm,total=\t,name=j}]
    \foreach \s in {1,...,\t}{(j-\s) node[circ](a\s){\s}};
\end{axis}
\end{tikzpicture}

当我运行代码时,我只得到两个交叉点,而不是 4 个。此外,当我尝试使用以下方法读取 X 值时,我遇到了太大的值

\pgfextra{
    \pgfextractx{\len}{\pgfpointdiff{\pgfplotspointaxisxy{0}{0}}{\pgfpointanchor{j-\s}{center}}}
    \pgfextractx{\plotwidth}{\pgfpointdiff{\pgfplotspointaxisxy{\getvalue{xmin}}{0}}%
    {\pgfplotspointaxisxy{\getvalue{xmax}}{0}}}%
    \pgfmathparse{\len*(\getvalue{xmax}-\getvalue{xmin})/\plotwidth}
    \global\let\macrox\pgfmathresult%
    \xdef\intsectX{\pgfmathresult}%
}

那么如何规范化X相交的值以及如何读取所有的相交点?

答案1

您陷入了 PGFPlots 的一个错误。以下是您可以避免此问题的方法。

% used PGFPlots v1.15
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \usetikzlibrary{
        intersections,
    }
    \pgfplotsset{
        compat=1.15,
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        width=0.75\textwidth,
        height=0.5\textwidth,
        xmin=0, xmax=29000,
        ymin=-10,ymax=10,
        xlabel={$k$},
        xlabel near ticks,
        ylabel near ticks,
        restrict y to domain=-11:11,
        restrict x to domain=0:24000,
        samples=101,
        axis x line=center,
        axis y line=left,
        scaled ticks=false, tick label style={
            /pgf/number format/fixed,
            /pgf/number format/1000 sep=\thinspace,
        },
        smooth,
    ]

            \def\nf{1.50}
            \def\ns{1.45}
            \def\nc{1.40}
            \def\d{0.0005}
            \def\lamda{0.0001}
            \def\k{2*pi/\lamda}

        \addplot [name path=Aymm] gnuplot [domain=1:25000] {
            ((sqrt((sqrt(((2*pi/\lamda)^(2)*\nf^(2))-x^(2)))^(2)-((2*pi/\lamda)^(2)*\ns^(2))))+(sqrt((sqrt(((2*pi/\lamda)^(2)*\nf^(2))-x^(2)))^(2)-((2*pi/\lamda)^(2)*\nc^(2)))))/((x-(sqrt((sqrt(((2*pi/\lamda)^(2)*\nf^(2))-x^(2)))^(2)-((2*pi/\lamda)^(2)*\ns^(2)))*(sqrt((sqrt(((2*pi/\lamda)^(2)*\nf^(2))-x^(2)))^(2)-((2*pi/\lamda)^(2)*\nc^(2))))/x)))
        };

        % create an invisible path to later find the intersections
        % for that use "not so much data points to avoid bug
        % <https://sourceforge.net/p/pgfplots/bugs/139/>
        \addplot [draw=none,name path=Symm] gnuplot [domain=1:25000] {tan(\d*x)};
        % now draw the real curve(s) using "a lot" of data points so that the
        % "infinite" path are clearly shown
        \addplot [magenta,samples=1001] gnuplot [domain=1:25000] {tan(\d*x)};

        \draw [
            name intersections={
                of=Aymm and Symm,
                total=\t,
                name=j,
            },
        ]
            \foreach \s in {1,...,\t} {
                (j-\s) node [
                    fill=black,
                    circle,
                    inner sep=1pt,
                    label={[blue]above:\s},
                ] (a\s) {}
            }
        ;
    \end{axis}
\end{tikzpicture}
\end{document}

该图显示了上述代码的结果

相关内容