# How to calculate the Hessian of the Lagrangian at x and lambda

I'm working on a project that needs to solve a constraint optimization function. Currently, I'm using Knitro solver and it needs to calculate the the hessian of the lagrangian at x and lambda. I don't understand how to calculate the hessian. The constraint optimization problem is as follows: $\text{minimize}_x 100 -(x_2 - x^2_1)^2 + (1-x_1)^2$ subject to $1\le x_1x_2$, $0\le x_1,x_2$,$x_1\le0.5$. The function to calculate the hessian is (it seems that lambda is given): $t = x_2 - x_1x_1;$ $h_1 = (-400.0 t) + (800.0 x_1x_1) + 2.0$, $h_2 = (-400.0 x_1) + \lambda_1$, $h_3 = 200.0 + \lambda_2 2.0)$ Could you please tell me how to get $h_1,h_2,h_3$ ? Thank you very much.

I read your constraints as $$0\leq x_1\leq {1\over2},\ x_2\geq0,\ x_1 x_2\geq1.$$ It follows that the feasible domain $B$ is bounded by the halfline $h_1: \ x_1={1\over2}$ starting upwards at the point $P:=({1\over2},2)$ and by a steep arc $h_2$ of the hyperbola $x_1 x_2=1$ starting at $P$ as well. The gradient of $f$ computes to $$\nabla f(x_1,x_2)=(\ldots, -2x_2+2x_1^2)\ .$$ It follows that $f$ has no stationary point in the interior of $B$, as $x_1\leq{1\over2}$ and $x_2\geq2$ there.
Along $h_1$ we have to consider the pullback $$\phi_1(x_2):=f\bigl({1\over2},x_2\bigr)=-x_2^2 +{1\over2} x_2+101.0625$$ which obviously is monotonically decreasing to $-\infty$ going up along $h_1$. Analogously we can study the pullback along $h_2$, which is more complicated: $$\phi(x_2)=f\bigl({1\over x_2},x_2\bigr)=101-x_2^2 -{1\over x_2^4}+{1\over x_2^2}\ .$$ It should be possible to show that $\phi_2$ decreases monotonically to $-\infty$ as well when going upwards along $h_2$.
Since in fact we have $\lim_{x_2\to\infty}f(x_1,x_2)=-\infty$ uniformly in $x_1$ for $0\leq x_1\leq{1\over2}$ it follows that your function assumes its maximum at the point $P$ and is unbounded from below on the feasible domain $B$.
For a problem $$\min f(x) \quad \text{subject to} \ c_i(x) \geq 0, \ i = 1, \ldots, m,$$ the Lagrangian is the function of two (vectors of) variables $$L(x,\lambda) := f(x) - \sum_{i=1}^m \lambda_i c_i(x).$$ There is one $\lambda_i$ per constraint. The "-" sign is important and assumes you wrote all the constraints in the form $c_i(x) \geq 0$. There's some ambiguity in the way you wrote your constraints, but let's assume your problem is \begin{align*} \min \ & 100−(x_2−x_1^2)^2+(1−x_1)^2 \\ \text{subject to} \ & x_1 x_2 - 1 \geq 0, \ x_1 \geq 0, \ \tfrac{1}{2} - x_1 \geq 0, \ x_2 \geq 0. \end{align*} You Lagrangian is $$L(x,\lambda) = 100−(x_2−x_1^2)^2+(1−x_1)^2 - \lambda_1 (x_1 x_2 - 1) - \lambda_2 x_1 - \lambda_3 (\tfrac{1}{2} - x_1) - \lambda_4 x_2.$$ All that's left is compute all the second partial derivatives of $L$ with respect to $x$ evaluated at $(x,\lambda)$, and that's the Hessian KNITRO is expecting. KNITRO will supply the values of $x$ and $\lambda$ at which it wants to evaluate the Hessian.