在 Tikz 中的特定点处绘制导数切线

在 Tikz 中的特定点处绘制导数切线

以下代码:

\begin{figure}[htbp]
    \centering
    \begin{tikzpicture}[yscale=2,domain=0:16,samples=500]
      \draw[tkblue,thick] plot (\x,{1-exp(-0.45*\x)*(cos(deg(sqrt(1-0.0001)*\x))+0.3/(sqrt(1-0.2^2))*sin(deg(sqrt(1-0.1^2)*\x)))}) node[right] {$f(\mathrm{x})$};
      \draw[very thin,gray] (0,-0.4) grid (16.1,2.4);
      \draw[->] (0,0) -- (16.2,0) node[right] {$\mathrm{x}$};
      \draw[->] (0,-0.5) -- (0,2.5) node[left] {$\mathrm{t}$};
      \draw[black,<->,thick] (0,2) -- (12,2);
      \draw[black,thick] (6,2.15) node{{\large $\mathrm{transienter}\,\,\mathrm{Vorgang}$}};
      \draw[black,<-,thick] (12,2) -- (16,2);
      \draw[black,thick] (14.5,2.15) node{{\large $\mathrm{eingeschwungener}\,\,\mathrm{Vorgang}$}};
      \draw[black,-,thick] (12,2.5) -- (12,0); 
      \end{tikzpicture}
      \caption{Ausgleichsvorgang eines Systems auf eine äußere Anregung des dynamischen Systems}
  \label{fig:transient_stationaer}
 \end{figure}

生成: 在此处输入图片描述

我想画出 (x=2, x=4, x=6, x=14) 处的导数切线。怎么做?

答案1

解释如下。我会

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}[yscale=2,domain=0:16,samples=101,
pics/tangent at/.style={code={
    \path[name path=l] (#1*1cm-1pt,0|-current bounding box.south)
      -- (#1*1cm-1pt,0|-current bounding box.north);
    \path[name path=r] (#1*1cm+1pt,0|-current bounding box.south)
      -- (#1*1cm+1pt,0|-current bounding box.north);
    \draw[pic actions,
        name intersections={of=\pgfkeysvalueof{/tikz/tangent pic/graph name} and l,by=li},
        name intersections={of=\pgfkeysvalueof{/tikz/tangent pic/graph name} and r,by=ri}]
       (li) -- (ri);}},
tangent pic/.cd,graph name/.initial=graph]
      \draw[blue,thick,name path=graph] plot (\x,{1-exp(-0.45*\x)*(cos(deg(sqrt(1-0.0001)*\x))+0.3/(sqrt(1-0.2^2))*sin(deg(sqrt(1-0.1^2)*\x)))}) node[right] {$f(x)$};
      \draw[very thin,gray] (0,-0.4) grid (16.1,2.4);
      \draw[->] (0,0) -- (16.2,0) node[right] {$x$};
      \draw[->] (0,-0.5) -- (0,2.5) node[left] {$t$};
      \draw[black,<->,thick] (0,2) -- (12,2);
      \draw[black,thick] (6,2.15) node[font=\large]{transienter Vorgang};
      \draw[black,<-,thick] (12,2) -- (16,2);
      \draw[black,thick] (14.5,2.15) node[font=\large]{eingeschwungener Vorgang};
      \draw[black,-,thick] (12,2.5) -- (12,0); 
      \path foreach \X in {2,4,6,14}
      {pic[red,thick,shorten <=-1cm,shorten >=-1cm]{tangent at=\X}};
\end{tikzpicture}
\end{document}

在此处输入图片描述

这里我去掉了一些\mathrms。

现在来解释一下。一种方法是使用这个答案

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{decorations.markings}
\tikzset{tangent/.style={% https://tex.stackexchange.com/a/25940
        decoration={
            markings,% switch on markings
            mark=
                at position #1
                with
                {
                    \coordinate (tangent point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt);
                    \coordinate (tangent unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt);
                    \coordinate (tangent orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1);
                }
        },
        postaction=decorate
    },
    use tangent/.style={
        shift=(tangent point-#1),
        x=(tangent unit vector-#1),
        y=(tangent orthogonal unit vector-#1)
    },
    use tangent/.default=1}
\begin{document}
\begin{tikzpicture}[yscale=2,domain=0:16,samples=101]
      \draw[blue,thick,tangent/.list={0.17,0.28,0.42,0.9}] plot (\x,{1-exp(-0.45*\x)*(cos(deg(sqrt(1-0.0001)*\x))+0.3/(sqrt(1-0.2^2))*sin(deg(sqrt(1-0.1^2)*\x)))}) node[right] {$f(\mathrm{x})$};
      \draw[very thin,gray] (0,-0.4) grid (16.1,2.4);
      \draw[->] (0,0) -- (16.2,0) node[right] {$\mathrm{x}$};
      \draw[->] (0,-0.5) -- (0,2.5) node[left] {$\mathrm{t}$};
      \draw[black,<->,thick] (0,2) -- (12,2);
      \draw[black,thick] (6,2.15) node{{\large $\mathrm{transienter}\,\,\mathrm{Vorgang}$}};
      \draw[black,<-,thick] (12,2) -- (16,2);
      \draw[black,thick] (14.5,2.15) node{{\large $\mathrm{eingeschwungener}\,\,\mathrm{Vorgang}$}};
      \draw[black,-,thick] (12,2.5) -- (12,0); 
      \foreach \X in {1,...,4}
      {\draw [red, thick, use tangent=\X] (-3,0) -- (3,0);}
\end{tikzpicture}
\end{document}

在此处输入图片描述

问题在于必须手动找到标记位置。另一种方法可能是这个答案,以这种形式适用于pgfplots。这是一个普通的 TiZ 版本。为了方便起见,我将其定义为pic,因此 e。

\pic[draw=red,thick,shorten <=-1cm,shorten >=-1cm]{tangent at=2};

足够了。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}[yscale=2,domain=0:16,samples=101,
pics/tangent at/.style={code={
    \path[name path=l] (#1*1cm-1pt,0|-current bounding box.south)
      -- (#1*1cm-1pt,0|-current bounding box.north);
    \path[name path=r] (#1*1cm+1pt,0|-current bounding box.south)
      -- (#1*1cm+1pt,0|-current bounding box.north);
    \draw[pic actions,
        name intersections={of=\pgfkeysvalueof{/tikz/tangent pic/graph name} and l,by=li},
        name intersections={of=\pgfkeysvalueof{/tikz/tangent pic/graph name} and r,by=ri}]
       (li) -- (ri);}},
tangent pic/.cd,graph name/.initial=graph]
      \draw[blue,thick,name path=graph] plot (\x,{1-exp(-0.45*\x)*(cos(deg(sqrt(1-0.0001)*\x))+0.3/(sqrt(1-0.2^2))*sin(deg(sqrt(1-0.1^2)*\x)))}) node[right] {$f(\mathrm{x})$};
      \draw[very thin,gray] (0,-0.4) grid (16.1,2.4);
      \draw[->] (0,0) -- (16.2,0) node[right] {$\mathrm{x}$};
      \draw[->] (0,-0.5) -- (0,2.5) node[left] {$\mathrm{t}$};
      \draw[black,<->,thick] (0,2) -- (12,2);
      \draw[black,thick] (6,2.15) node{{\large $\mathrm{transienter}\,\,\mathrm{Vorgang}$}};
      \draw[black,<-,thick] (12,2) -- (16,2);
      \draw[black,thick] (14.5,2.15) node{{\large $\mathrm{eingeschwungener}\,\,\mathrm{Vorgang}$}};
      \draw[black,-,thick] (12,2.5) -- (12,0); 
      \path foreach \X in {2,4,6,14}
      {pic[red,thick,shorten <=-1cm,shorten >=-1cm]{tangent at=\X}};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容