我正在尝试找到用 tikz 制作的平滑曲线的最小点,这样我就可以用一个点来标记它,但是平滑曲线会稍微移动最小值和最大值。我当然可以只移动这些点,但我想知道是否有一个聪明的方法来做到这一点。
\begin{tikzpicture}
%Opsætning af koordinater
\coordinate (bottom) at (5,1);
\coordinate (lmen) at (3 , 2.75);
\coordinate (lman) at (4.5 , 3.25);
\coordinate (rmen) at (6.7,3.35);
\coordinate (rman) at (6.15,4.75);
\coordinate (lkant) at (0,4.756);
\coordinate (rkant) at (7,4.55);
\coordinate (o) at (0,0);
\coordinate (x) at (7,0);
\coordinate (y) at (0,5);
%tegn grafsystem
\draw [<->] (y) -- node [rotate=90, above] {Energy of konfiguration} (o) -> node [below] {Place in konfiguration space} (x);
\node [rotate = 90] at (-0.1,2.5) {Energy of konfiguration};
% Selve energikurven
\draw [green!80] plot [smooth] coordinates {(lkant) (lmen) (lman) (bottom) (rman) (rmen) (rkant)};
%lagels og sådant
\filldraw[color = blue!50] (bottom) circle (0.1) node [below,color=black] {\tiny Global minima};
\filldraw [color = red!50] (lmen) circle (0.1) node [below,color=black] {\tiny Local minima trap};
\filldraw [color = red!50] (rmen) circle (0.1) node [below,color=black] {\tiny Local minima trap};
\filldraw [color = yellow!50] (lman) circle (0.1) node [above,color=black] {\tiny Local maxima};
\filldraw [color = yellow!50] (rman) circle (0.1) node [above,color=black] {\tiny Local maxima};
\end{tikzpicture}
制作图片
答案1
下面的示例指定曲线的输入和输出角度,以确保点分别为最小值和最大值:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%Opsætning af koordinater
\coordinate (bottom) at (5,1);
\coordinate (lmen) at (3 , 2.75);
\coordinate (lman) at (4.5 , 3.25);
\coordinate (rmen) at (6.7,3.35);
\coordinate (rman) at (6.15,4.75);
\coordinate (lkant) at (0,4.756);
\coordinate (rkant) at (7,4.55);
\coordinate (o) at (0,0);
\coordinate (x) at (7,0);
\coordinate (y) at (0,5);
%tegn grafsystem
\draw [<->] (y) -- node [rotate=90, above] {Energy of konfiguration} (o) -> node [below] {Place in konfiguration space} (x);
% Selve energikurven
% \draw [green!80] plot [smooth, tension=.2] coordinates {(lkant) (lmen) (lman) (bottom) (rman) (rmen) (rkant)};
\draw [green!80, in=180, out=0, tension=.1]
(lkant)[out=-10] to (lmen) to (lman) to (bottom) to (rman) to (rmen) to (rkant);
%lagels og sådant
\filldraw[color = blue!50] (bottom) circle (0.1) node [below,color=black] {\tiny Global minima};
\filldraw [color = red!50] (lmen) circle (0.1) node [below,color=black] {\tiny Local minima trap};
\filldraw [color = red!50] (rmen) circle (0.1) node [below,color=black] {\tiny Local minima trap};
\filldraw [color = yellow!50] (lman) circle (0.1) node [above,color=black] {\tiny Local maxima};
\filldraw [color = yellow!50] (rman) circle (0.1) node [above,color=black] {\tiny Local maxima};
\end{tikzpicture}
\end{document}
黄色标记的局部最大值和其后的最小值之间的水平距离太小,无法获得不向后弯曲的平滑曲线。
例如:
\coordinate (lkant) at (0,4.756);
\coordinate (lmen) at (1.8, 2.75);
\coordinate (lman) at (3.1, 3.25);
\coordinate (bottom) at (4.1, 1);
\coordinate (rman) at (5.6, 4.75);
\coordinate (rmen) at (6.4, 3.35);
\coordinate (rkant) at (7, 4.55);
...
\draw [green!80, in=180, out=0, tension=.1]
(lkant)[out=-10] to (lmen) to (lman) to (bottom) to (rman) to (rmen)
to [in=245](rkant);