你能帮我画出这个不等式的区域吗:
\begin{eqnarray}
3x_1 + 3x_2 \geq 27
x_1 + 2x_2 \geq 18
4x_1 + 2x_2 \geq 28
\end{eqnarray}
我需要两个图表:一个包含三个用不同模式标记的不等式,另一个包含解的集合。
受到对另一个问题的答案的启发,我做了类似的事情:它有效,但我无法在下面写任何东西,当我尝试改变它时它只会显示解决方案,但这没有用。
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\makeatletter
\newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis}
\makeatother
\pgfplotsset{only axis on top/.style={axis on top=false, after end axis/.code={
\pgfplotsset{axis line style=opaque, ticklabel style=opaque, tick style=opaque,
grid=none}\pgfplotsdrawaxis}}}
\newcommand{\drawge}{-- (rel axis cs:1,0) -- (rel axis cs:1,1) -- (rel axis cs:0,1) \closedcycle}
\begin{document}
\begin{figure}[htpb]
\centering
\label{fig:p3:c1}
\begin{tikzpicture}
\begin{axis}[only axis on top,
axis line style=very thick,
axis x line=bottom,
axis y line=left,
ymin=0,ymax=14,xmin=0,xmax=14,
xlabel=$x_1$, ylabel=$x_2$,grid=major
]
\addplot [draw=none, pattern=vertical lines, domain=0:14]
{9-x} \drawge;
\addplot [draw=none, pattern=north west lines, domain=0:14]
{9-0.5*x} \drawge;
\addplot [draw=none, pattern=horizontal lines, domain=0:14]
{14-2*x} \drawge;
\addplot[very thick, domain=0:14] {9-x};
\addplot[very thick, domain=0:14] {9-0.5*x};
\addplot[very thick, domain=0:14] {14-2*x};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
答案1
以下是 的一种方法pstricks
。我简化了不等式:
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\pagestyle{empty}
\usepackage{array}
\usepackage[svgnames, x11names]{pstricks}%
\usepackage{pstricks-add, pst-eucl}
\usepackage{auto-pst-pdf}
\begin{document}
\everypsbox{\footnotesize}
\psset{labels=none, unit=0.25}
\psset{PointName=none, PointSymbol=none, nodesepA=-20, nodesepB=-20}
\begin{pspicture*}(-10,-10)(26,24)
\psaxes[ticks=none]{->}(0,0)(-10,-10)(26,24)[$x_1$,-120][$x_2$,-140]
\psset{linecolor=IndianRed}
\pnodes{K}(-10,-10)(-10,24)(26,24)(26,-10)
\pnodes{A}(7,0)(9,0)(18,0)
\pnodes{B}(0,0)(0,9)(0,14)
\uput[dl](B0){$O$}
\pstLineAB[linecolor=IndianRed3]{A1}{B1}\uput[d](A1){9}\uput[l](B1){9}
\pstLineAB[linecolor=Coral2]{A2}{B1}\uput[d](A2){18}
\pstLineAB[linecolor=PeachPuff2]{A0}{B2}\uput[d](A0){7}\uput[l](B2){14}
%%Inequalities
\psset{linestyle=none, fillstyle=solid, opacity=0.25, framesize=15pt 5pt }
%%1st inequality
\pstInterLL{K0}{K1}{A1}{B1}{C}
\pstInterLL{K0}{K3}{A1}{B1}{D}
\pspolygon[fillcolor= IndianRed](C)(K1)(K2)(K3)(D)
%%2nd inequality
\pstInterLL{K0}{K1}{A2}{B1}{E}
\pstInterLL{K2}{K3}{A2}{B1}{F}
\pspolygon[fillcolor= Coral2](E)(K1)(K2)(K3)(F)
%%3rd inequality
\pstInterLL{K1}{K2}{A0}{B2}{G}
\pstInterLL{K0}{K3}{A0}{B2}{H}
\pspolygon[fillcolor= PeachPuff3](G)(K2)(K3)(H)
%% Legend
\rput(-5,-5){\setlength\arraycolsep{0.8em}$\begin{array}{@{}l l@{}}%
\fnode*[linecolor=IndianRed](0,1.25pt){In1} & x_1 + x_2 \ge 9 \\
\fnode*[linecolor=Coral2](0,1.25pt){In2} & x_1 + 2x_2 \ge 18\\
\fnode*[linecolor=PeachPuff2](0,1.25pt){In2} & 2x_1 + x_2 \ge 14
\end{array} $}
\end{pspicture*}
\end{document}
答案2
正如 cmhughes 指出的那样,他已经写了一个解决方案我已经适应了你的代码:
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{patterns,intersections}
\makeatletter
\newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis}
\makeatother
\pgfplotsset{only axis on top/.style={axis on top=false, after end axis/.code={
\pgfplotsset{axis line style=opaque, ticklabel style=opaque, tick style=opaque,
grid=none}\pgfplotsdrawaxis}}}
\newcommand{\drawge}{-- (rel axis cs:1,0) -- (rel axis cs:1,1) -- (rel axis cs:0,1) \closedcycle}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{figure}[htpb]
\centering
\label{fig:p3:c1}
\begin{tikzpicture}
\begin{axis}[only axis on top,
axis line style=very thick,
axis x line=bottom,
axis y line=left,
ymin=0,ymax=14,xmin=0,xmax=14,
xlabel=$x_1$, ylabel=$x_2$,grid=major
]
\addplot [draw=none, pattern=vertical lines, domain=0:14]
{9-x} \drawge;
\addplot [draw=none, pattern=north west lines, domain=0:14]
{9-0.5*x} \drawge;
\addplot [draw=none, pattern=horizontal lines, domain=0:14]
{14-2*x} \drawge;
\addplot[very thick, domain=0:14] {9-x};
\addplot[very thick, domain=0:14] {9-0.5*x};
\addplot[very thick, domain=0:14] {14-2*x};
\end{axis}
\end{tikzpicture}
\end{figure}
\begin{figure}[htpb]
\centering
\label{fig:p3:c1}
\begin{tikzpicture}
\begin{axis}[only axis on top,
axis line style=very thick,
axis x line=bottom,
axis y line=left,
ymin=0,ymax=14,xmin=0,xmax=14,
xlabel=$x_1$, ylabel=$x_2$,grid=major
]
\addplot[name path global=firstline, very thick, domain=0:14] {9-x};
\addplot[name path global=secondline, very thick, domain=0:14] {9-0.5*x};
\addplot[name path global=thirdline, very thick, domain=0:14] {14-2*x};
%Repeat next line with a different pattern to show a pattern mixture
%over this region.
\fill[name intersections={of=secondline and thirdline, by=pointtwo}][pattern=vertical lines] (rel axis cs:0,1) -- (pointtwo)--(14,2)|-cycle;
\end{axis}
\end{tikzpicture}
\end{figure}\end{document}