I'm trying to extremise the functional
$$ S = \int L(Q_i) \, dx\,dy $$
Where the $Q_i$ are functions of $x$ and $y$, subject to the constraint
$$ \vec{\nabla} \cdot \vec{Q} = A(x,y) \,.$$
My approach has been to define the functional
$$F = \int \vec{\nabla} \cdot \vec{Q} - A(x,y) \, dx \,dy $$
Which means the constraint can be written as $F = 0$. Then to solve the problem we need to extremise without constraint the functional
$$ S + \lambda F$$
for some Lagrange multiplier $\lambda$. That is, we need to solve
$$ \frac{\delta S}{\delta Q_i} + \lambda \frac{\delta F}{\delta Q_i} = 0$$
for each $i$. However, because of the nature of $F$, its functional derivative is identically zero. This means that my Lagrange multiplier drops completely out of the problem, which can't be right. I have found answers to this question and the approach they take is to treat $\lambda = \lambda(x,y)$ as a function of $x$ and $y$, bringing it inside the integral in the expression for $F$. Then the variation of $F$ includes terms like
$$ \frac{\partial \lambda}{\partial x} \,.$$
I've never seen anything like this before --- I have always treated the Lagrange multiplier as some constant that sits outside the integral. Can anybody explain what is going on?
Thank you.