I want to solve the following two-variate nonlinear programming using KKT conditions: $$ \begin{align} \begin{split} \max \quad & 15 \sqrt{x_{1}} + 16 \sqrt{x_{2}} \\ \text{s.t.} \quad & x_{1} + x_{2} \leq 120 \\ & x_{1}, x_{2} \in \mathbb{R}^+ \end{split} \end{align} $$
Two parts in the function $L(x_{1}, x_{2}, \lambda)$ are monotonically increasing, so the function is strictly concave. It is obvious that the decision variables belong to a convex set.
Point (1, 1) is a slater point, so the problem satisfies Slater's condition. The strong duality holds.
The Lagrangian function is: $$ \begin{align} \begin{split} L(x_{1}, x_{2}, \lambda) = 15 \sqrt{x_{1}} + 16 \sqrt{x_{2}} - \lambda (x_{1} + x_{2} - 120) \end{split} \end{align} $$ whose derivatives are: $$ \begin{align} \begin{split} \frac{\partial L}{\partial x_{1}} &= \frac{15}{2 \sqrt{x_{1}}} - \lambda \\ \frac{\partial L}{\partial x_{2}} &= 8 / \sqrt{x_{2}} - \lambda \\ \frac{\partial L}{\partial \lambda} &= 120 - x_{1} - x_{2} \end{split} \end{align} $$
Also: $$ \begin{align} x_1, x_2 \geq 0 \\ \lambda \geq 0 \end{align} $$
Critical points can be calculated by the symbolic math toolbox in MATLAB:
syms x1 x2 lbd
eq(1) = lbd * (120 - x1 - x2) == 0;
eq(2) = x1 * (15/2/sqrt(x1) - lbd) == 0;
eq(3) = x2 * (8/sqrt(x2) - lbd) == 0;
sol = solve(eq)
Results are (0, 0, 0), (120, 0, 0.6847), (0, 120, 0.7303), and (56.133, 63.867, 1.0010), and corresponding values of the objective function are 0, 164.3168, 175.2712, and 240.2499. So the point (56.133, 63.867, 1.0010) is chosen as the optimal solution.
Specifically, I have three questions:
- Is my writing good enough?
- Do I have to solve KKT conditions regarding inequality? MATLAB can't solve the following system of equations because of
Division by zero
.
eq(1) = lbd1 * (120 - x1 - x2) == 0;
eq(2) = x1 + x2 - 120 <= 0
eq(3) = x1 * (15/2/sqrt(x1) - lbd1) == 0;
eq(4) = 15/2/sqrt(x1) - lbd1 <= 0;
eq(5) = x2 * (8/sqrt(x2) - lbd1) == 0;
eq(6) = 8/sqrt(x2) - lbd1 <= 0;
- What if the problem becomes complicated? Are there any softwares to analyse NLPs this way?
Two minor errors pointed out by @prubin and @dhasson are not the primary issue of this post, so I have corrected them. Much appreciated.