# Recover Lagrange multiplier values for known values in quadratic energy minimization

## weblog/

Often I'm minimizing energies of the form:
``````E = ½ xT yT Q x + xTyT b
y
``````
where `Q` is a quadratic coefficient matrix, `b` is a vector of linear coefficients, `x` are unknown, and y are known. Now normally if I just want to minimize this energy I treat the known values (`y`) as constants and take the derivative with respect to the unknowns (`x`) and set it to zero. Then I just move all the terms involving `y` to the right hand side. However if I'd like to know how setting these known values affected the energy minimization then its useful to treat the known values not as constant but as constraints. So I have the same energy as above, where now both `x` and `y` are variables, but subject to the constraints that
``````y = y*
``````
where `y*` are the known values of `y`. I can enforce these via Lagrange multipliers. Then once I've found my solution the values of the Lagrange multipliers corresponding to each `y` will tell me the effect of that `y`'s constraint on the energy minimization. The problem now becomes finding the saddle point (equilibrium) of the following Lagrangian:
``````Λ = ½ xT yT Q x + xTyT b + λT y - λT y*
y
``````
Or equivalently by repeating the `λTy` terms:
``````Λ = ½ xT yT λT Qxx Qxy 0 x + xTyT λT bx
Qyx Qyy I y           by
0   I   0 λ          -y*
``````
Now, let's start to take derivatives with respect to each of the sets of variables. We begin with `λ`. Setting `∂Λ/∂λT = 0` gives us:
``````∂Λ    0 I 0 x + -y*
--- =       y       = 0
∂λT         λ
``````
which reduces simply to revealing our known values:
``````y = y*
``````
Now look at setting `∂Λ/∂xT = 0` which gives us:
``````∂Λ    Qxx Qxy 0 x + bx
--- =           y       = 0
∂xT             λ
``````
which after substituting our result `y=y*` reduces to the system of equations we are used to seeing when minimizing quadratic energies with fixed values:
``````Qxx x = -bx - Qxy y*
``````
So we can invert `Qxx` and solve for `x`:
``````x* = Qxx-1 ( -bx - Qxy y* )
``````
Now `x` and `y` are known, all that's left is to solve for `λ` by taking the last set of derivatives. So we set `∂Λ/∂yT = 0` which gives us:
``````∂Λ    Qyx Qyy I x + by
--- =           y       = 0
∂yT             λ
``````
Plugging in our known values and moving them to the right-hand side reveals the values of `λ`:
``````λ* = - Qyx x* - Qyy y* - by
``````
The great thing about all of this is that you don't have to do anything extra. If you're already set up to immediately solve for `x` treating `y` as constant you've got everything you need to determine the values of `λ` without every actually implementing the equivalent Lagrangian.