4. Let real numbers $x, y$ satisfy the system of inequalities $\left\{\begin{array}{l}x-y \leqslant 0, \\ 4 x-y \geqslant 0, \\ x+y \leqslant 3,\end{array}\right.$ then the maximum value of $z=x+2 y-\frac{1}{x}$ is
A. $\frac{77}{6}$
B. $\frac{56}{15}$
C. $\frac{23}{6}$
D. 4
Solve:
Draw the feasible region as shown in the figure. The function $y=\frac{1}{2}\left(\frac{1}{x}-x+z\right)$ is monotonically decreasing. When the graph is tangent to the line $x+y=3$, the value of $z$ is maximized. Solving the system $\left\{\begin{array}{l}y=\frac{1}{2}\left(\frac{1}{x}-x+z\right), \\ y=3-x\end{array} \Rightarrow x^{2}+(z-6) x+1=0\right.$. $\Delta=(z-6)^{2}-4=0 \Rightarrow z=4$, so the answer is $D$.