
일부 선형 함수 사이의 영역을 채우려고 합니다. 그러나 결과 채우기가 이상해 보입니다. 다음은 코드입니다:
\usepackage{amsmath}
\usepackage{systeme}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.16}
\begin{document}
\section{Problem 2:}
Because all the constraints as well as the function to maximize are linear, by the graphical method, we only need to check corners of the feasible region, which looks like:
\bigskip
\begin{tikzpicture}
\begin{axis}[
axis lines = left,
xlabel = $x_1$,
ylabel = $x_2$,
ymin=0, ymax=10
]
%Below the first constraint is defined
\addplot [name path=red,
domain= 0:15,
samples=100,
color=red,
]
{(x -4)/2};
%Here the second constraint is defined
\addplot [name path=blue,
domain=0:15,
samples=100,
color=blue,
]
{3+x};
%Here the third constraint is defined
\addplot [name path=green,
domain= 0:15,
samples=100,
color=green,
]
{2};
\path[name path=redgreen,
intersection segments={of=red and green,
sequence=A1 -- B0,},
];
\addplot [gray] fill between[of = blue and redgreen];
\end{axis}
\end{tikzpicture}
\end{document}
이 코드는 생산
누군가 무슨 일이 일어났는지 설명하고 고치려고 노력할 수 있나요? 빨간색, 녹색, 파란색 선 사이의 영역만 채우고 싶습니다. 정말 고마워요!
답변1
언급된 내용이 없으므로 문서 클래스를 기사로 가정했습니다.
\documentclass{article}
\usepackage{amsmath}
\usepackage{systeme}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.16}
\begin{document}
\section{Problem 2:}
Because all the constraints as well as the function to maximize are linear, by the
graphical method, we only need to check corners of the feasible region, which looks
like:
\bigskip
\begin{tikzpicture}
\begin{axis}[
axis lines = left,
xlabel = $x_1$,
ylabel = $x_2$,
ymin=0, ymax=10
]
%Below the first constraint is defined
\addplot [name path=red,
domain= 0:15,
samples=100,
color=red,
]
{(x -4)/2};
%Here the second constraint is defined
\addplot [name path=blue,
domain=0:15,
samples=100,
color=blue,
]
{3+x};
%Here the third constraint is defined
\addplot [name path=green,
domain= 0:15,
samples=100,
color=green,
]
{2};
\path [
name path=gr,
intersection segments={of=green and red,
sequence={L1 -- R2}%------the first segment of green and second segment of red
}];
\addplot [gray] fill between[of = blue and gr];
\end{axis}
\end{tikzpicture}
\end{document}