Differentiating an integral with respect to a function If we have $Q(z)$ and $P(z)$   functions of $z$ and $a, b, \lambda, I$ constants. How would you differentiate
$$\int_0^1 aQ(z) - \frac{1}{2} bQ(z)^2 \, dz - \lambda \left(I - \int_0^1 P(z)Q(z) \, dz \right)$$
with respect to $Q(z)$?
The answer turns out to be $a - bQ(z) - \lambda P(z)$ but I can't see how they got there?
I tried the Leibniz integral rule but this just reduces to integrating a function of $Q(z)$ with respect to z but of course w don't know what the function $Q(z)$ is!
 A: $\newcommand{\+}{^{\dagger}}
 \newcommand{\angles}[1]{\left\langle\, #1 \,\right\rangle}
 \newcommand{\braces}[1]{\left\lbrace\, #1 \,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\, #1 \,\right\rbrack}
 \newcommand{\ceil}[1]{\,\left\lceil\, #1 \,\right\rceil\,}
 \newcommand{\dd}{{\rm d}}
 \newcommand{\down}{\downarrow}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,{\rm e}^{#1}\,}
 \newcommand{\fermi}{\,{\rm f}}
 \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,}
 \newcommand{\half}{{1 \over 2}}
 \newcommand{\ic}{{\rm i}}
 \newcommand{\iff}{\Longleftrightarrow}
 \newcommand{\imp}{\Longrightarrow}
 \newcommand{\isdiv}{\,\left.\right\vert\,}
 \newcommand{\ket}[1]{\left\vert #1\right\rangle}
 \newcommand{\ol}[1]{\overline{#1}}
 \newcommand{\pars}[1]{\left(\, #1 \,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\pp}{{\cal P}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\vphantom{\large A}\,#2\,}\,}
 \newcommand{\sech}{\,{\rm sech}}
 \newcommand{\sgn}{\,{\rm sgn}}
 \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}}
 \newcommand{\ul}[1]{\underline{#1}}
 \newcommand{\verts}[1]{\left\vert\, #1 \,\right\vert}
 \newcommand{\wt}[1]{\widetilde{#1}}$
$$
\mbox{Lets}\quad
{\cal J}\bracks{Q}
\equiv
\int_{0}^{1}\bracks{a\,{\rm Q}\pars{z} - \half\,b\,{\rm Q}\pars{z}^{2}}\,\dd z
-\lambda\bracks{I - \int_{0}^{1}{\rm P}\pars{z}{\rm Q}\pars{z}\,\dd z}
$$

$$
\delta{\cal J}
=
\int_{0}^{1}\bracks{a - b\,{\rm Q}\pars{z} + \lambda{\rm P}\pars{z}}
\delta{\rm Q}\pars{z}\,\dd z
$$

$$
\color{#66f}{\large%
{\delta{\cal J} \over \delta{\rm Q}\pars{z}}=a - b\,{\rm Q}\pars{z}
+ \lambda\,{\rm P}\pars{z}}
$$

It's analogous to the "discrete version":
  $$
\partiald{}{Q_{i}}\sum_{j}f_{j}\,Q_{j}
=\sum_{j}f_{j}\,\partiald{Q_{j}}{Q_{i}}
=\sum_{j}f_{j}\,\delta_{ji} = f_{i}
$$

See Functional Derivative.
A: First let me try clarify what (I think) the question means by "differentiate wrt $Q(z)$". In calculus of variations often we perturb a function using another arbitrary function and one parameter, say perturbing $Q$ in the direction of $h$: $$\tilde Q(z|\varepsilon)= Q(z)+\varepsilon\cdot h(z).$$
Now we take derivative of the following expression with respect $\varepsilon$ at the point $\varepsilon=0$.
$$\int_0^1 a\tilde Q(z|\varepsilon) - \frac{1}{2} b\tilde Q(z|\varepsilon)^2 \, dz - \lambda \left(I - \int_0^1 P(z)\tilde Q(z|\varepsilon) \, dz \right)$$
we get:
$$\int_0^1 (a -  b Q(z)^2)\cdot h(z) \, dz +\lambda \cdot  \int_0^1 P(z)\cdot h(z) \, dz= \int_0^1 \left(a -  b Q(z)^2+\lambda \cdot   P(z) \right)\cdot h(z)\,dz $$
It is somewhat similar to what you have but notice even if for $h(z)=1$, you still have to write the integral.
