![可行區域](https://rvso.com/image/472714/%E5%8F%AF%E8%A1%8C%E5%8D%80%E5%9F%9F.png)
我想繪製可行區域。但我不知道該怎麼辦。我需要指導。
\documentclass[tikz, border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[gray!50, thin, step=0.5] (-1,-3) grid (5,4);
\draw[very thick,->] (-1,0) -- (5.2,0) node[right] {$x_1$};
\draw[very thick,->] (0,-3) -- (0,4.2) node[above] {$x_2$};
\foreach \x in {-1,...,5} \draw (\x,0.05) -- (\x,-0.05) node[below] {\tiny\x};
\foreach \y in {-3,...,4} \draw (-0.05,\y) -- (0.05,\y) node[right] {\tiny\y};
\draw (-1,-3) -- node[above,sloped] {\tiny$x_1=-1$} (-1,3);
\draw (0,0) -- node[above,sloped] {\tiny$x_1\leq x_2$} (3,3);
\draw (0,0) -- node[above,sloped] {\tiny$x_1\leq x_2$} (3,-3);
\draw (-1,3) -- node[above,sloped] {\tiny$x_2=3$} (3,3);
\draw (-1,3) -- node[above,sloped] {\tiny$x_2=-3$} (3,3);
\end{tikzpicture}
\end{document}
目前結果:
答案1
我不確定結果應該是什麼樣子,但這也許可以幫助你。
如果要繪製一個區域,則應該連接代表該區域邊界的線,否則您得到的只是未連接的單條線。另外,如果該區域不應覆蓋圖表的某些部分,則應將其放置在不應覆蓋的區域之前:
\documentclass[tikz, border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[gray!50, thin, step=0.5] (-1,-3) grid (5,4);
\draw[fill=gray!10]
(-1,-3)
-- node[above, sloped] {\tiny$x_1=-1$} (-1,3)
-- node[above, sloped] {\tiny$x_2=3$} (3,3)
-- node[above, sloped] {\tiny$x_1\leq x_2$} (0,0)
-- node[above, sloped] {\tiny$x_1\leq -x_2$} (3,-3)
-- node[above, sloped] {\tiny$x_2=-3$} cycle;
\draw[very thick, ->] (-1,0) -- (5.2,0) node[right] {$x_1$};
\draw[very thick, ->] (0,-3) -- (0,4.2) node[above] {$x_2$};
\foreach \x in {-1,...,5}
\draw (\x,0.05) -- (\x,-0.05)
\ifnum\x=0\relax
node[below right] {\tiny\x}
\else
node[below] {\tiny\x}
\fi ;
\foreach \y in {-3,...,4}
\draw (-0.05,\y) -- (0.05,\y)
\ifnum\y=0\else
node[right] {\tiny\y}
\fi ;
\draw[very thick, <->]
(0:2) arc[start angle=0, end angle=45, radius=2]
node[midway, right] {\tiny$q$};
\node[align=center] at (3,-2) {unstable \\ region};
\node[align=center] at (1,-2) {stable \\ region};
\end{tikzpicture}
\end{document}
刪除大部分標籤和網格後,它更像您顯示的圖片:
\documentclass[tikz, border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[fill=gray!10]
(-1,-3) -- (-1,3) -- (3,3) -- (0,0) -- (3,-3) -- cycle;
\draw[very thick, ->] (-1,0) -- (3,0) node[right] {$x_1$};
\draw[very thick, ->] (0,-3) -- (0,3.5) node[above] {$x_2$};
\draw[very thick, <->]
(0:2) arc[start angle=0, end angle=45, radius=2]
node[midway, right] {$q$};
\node[align=center] at (3,-2) {unstable \\ region};
\node[align=center] at (1,-2) {stable \\ region};
\end{tikzpicture}
\end{document}