<s>[INST] Derivative of an integral with change of variable. I have this problem.
I want to compute the following integral in terms of $z$, where $x = az$
$$
\frac{d}{da}\int a^2x^2dx
$$
Computing the integral first, the derivative as the last passage, I obtain what I believe to be the correct solution, i.e.,
$$
\frac{d}{da}\int a^2x^2dx = \frac{d}{da}\left(a^2 \frac{x^3}{3}\right) = \frac{d}{da}\left(a^2 \frac{a^3z^3}{3} + c\right) = 5a^4\frac{z^3}{3}
$$
and the same by substituting first in the integral, keeping in mind that $dx = a dz$,
$$
\frac{d}{da}\int a^2x^2dx = \frac{d}{da}\int a^2(az)^2 adz \frac{d}{da}\int a^5z^2 dz = \frac{d}{da}\left(a^5 \frac{z^3}{3}\right) = 5a^4\frac{z^3}{3}.
$$
Things start to get messy when I take the derivative inside the integral, i.e.,
$$
\frac{d}{da}\int a^2x^2dx = \int 2ax^2dx = \int 2a a^2z^2 adz = 2a^4\frac{z^3}{3}.
$$
One might argue that I need to keep in consideration also of $d/da x$, since $x$ depends on $a$, after all. However, I still obtain a wrong result
$$
\frac{d}{da}\int a^2x^2dx = \int a^2 \frac{d}{da}\left(x^2\right) + 2a x^2 dx = \int \left( a^2 \frac{d}{da}\left(a^2z^2\right) + 2a a^2z^2  \right)adz \\
= \int 2a^4z^2 + 2a^4z^2dz = 4a^4\frac{z^3}{3}.
$$
Since I am obtaining three different results, I must be making at least two different mistakes; I wonder where these mistakes are. (sorry for being lazy and not including the constant $c$ from the integrals)
 [/INST] We substitute $x=az$ right from the beginning and obtain
\begin{align*}
\color{blue}{\frac{d}{da}\int a^2x^2dx}&=\frac{d}{da}\int a^2(az)^2d(az)\\
&=\frac{d}{da}\left(a^5\int z^2 dz\right)\tag{1}\\
&=\left(\int z^2 dz\right)\left(\frac{d}{da} a^5\right)\tag{2}\\
&\,\,\color{blue}{=\left(\frac{1}{3}z^3+C\right)\left(5a^4\right)}\tag{3}\\
\end{align*}
Comment:

*

*In (1) we use $d(az)=adz$ and factor out $a$.


*In (2) we factor out the constant part.


*In (3) we integrate and differentiate.

Next we look at OPs final approach somewhat more detailed. Since OP wants to compute the integral with respect to $z$ we consider $x=x(z)=az$ as function of $z$. We obtain
\begin{align*}
\frac{d}{da}\int a^2x^2\,dx&=\frac{d}{da}\int a^2x^2(z)\,d\left(x(z)\right)\\
&=\frac{d}{da}\int a^2 x^2(z) x^{\prime}(z)\,dz\tag{4}
\end{align*}

We are now ready to do the differentiation with respect to $a$ before the integration. To better see what's going on we write
$x=x(z,a)$ and $x_z(z,a)$ instead of $x^{\prime}(z)$ to indicate that we differentiate with respect to $z$.

We obtain from (4) by successively applying the multiplication rule $(u\,v)^{\prime}=u^\prime v+uv^\prime$
\begin{align*}
\color{blue}{\frac{d}{da}}&\color{blue}{\int a^2 x^2(z,a) x_z(z,a)dz}\\
&=\int \frac{d}{da} \left(a^2 \cdot \left(x^2(z,a) x_z(z,a)\right)\right)dz\\
&=\int 2a \left(x^2(z,a) x_z(z,a)\right)dz\\
&\qquad +\int a^2\frac{d}{da}\left(x^2(z,a) x_z(z,a)\right)dz\\
&=\int 2a \left(x^2(z,a) x_z(z,a)\right)dz\\
&\qquad +\int a^2 \left(2x(z,a) \left(\frac{d}{da}x(z,a)\right) x_z(z,a) +x^2(z,a)\frac{d}{da} x_z(z,a)\right)dz\\
&=\int 2a \left((az)^2 a\right)dz\\
&\qquad +\int a^2 \left(2(az)\left(z\right) a + (az)^2\cdot 1\right)dz\\
&=2a^4\int z^2\,dz+2a^4\int z^2\,dz + a^4 \int z^2dz\\
&=5a^4\int z^2dz\\
&\,\,\color{blue}{=5a^4\left(\frac{1}{3}z^3+C\right)}
\end{align*}
in accordance with (3).

</s>