# Derivative of a summation

I need to compute the derivative of this function:

$f(\alpha) = \sum_{i=1}^n \left[U_i - U_0 \left( \frac{h_i}{h_0} \right)^\alpha \right]^2$

where $h_0$ and $U_0$ are constant. I thought it was

$\frac{d}{d\alpha} f(\alpha) = -2 \sum_{i=1}^n \left[U_i - U_0 \left( \frac{h_i}{h_0} \right)^\alpha \right] \alpha U_0 \left( \frac{h_i}{h_0} \right)^{\alpha-1}$

but i don't know why, when i plot this with MATLAB i find something that is obviously not the derivative of $f(\alpha)$

Where am I wrong?

Thank you very much

-

Your inner derivative is wrong. The derivative of $$k^\alpha = \exp(\alpha \log k)$$ with respect to $\alpha$ is $$\exp(\alpha \log k) \log k = \log k \cdot k^\alpha$$ not $\alpha k^{\alpha - 1}$. So the derivative should be $$-2\sum_{i=1}^n \left[ U_i - U_0 \left(\frac{h_i}{h_0}\right)^{\alpha}\right]U_0\left(\frac{h_i}{h_0}\right)^\alpha \cdot \log \frac{h_i}{h_0}$$