Lagrange multiplier

To minimise f(x), subject to the constraint g(x) = c, consider
Λ(x, λ) = f(x) + λ { g(x) - c }.
λ is known as the "Lagrange multiplier."
 
Solve
∇ Λ(x, λ) = (∂Λ/∂x1, ..., ∂Λ/∂xn, ∂Λ/∂λ) = 0
 
For example, given positive integers {n1, ..., nk}, minimise
n1 log p1 + ... + nk log pk
subject to
p1 + ... + pk = 1,
let
Λ(p, λ) = n1 log p1 + ... + nk log pk + λ{p1 + ... + pk - 1},
∇ Λ = (n1/p1 + λ, ..., nk/pk + λ, p1 + ... + pk - 1) = 0,
so
pi = - ni / λ ∝ ni   (λ can be negative)
and
∑ pi = 1,
giving
pi = ni / ∑j nj   (and λ = - ∑j nj).
(Also see the [multinomial] probability distribution.)