I have the simple function:
$$ f=\ln(ka^k) $$
Here are two methods of taking the derivative with respect to $k$:
Method 1:
$$ \frac{\partial f}{\partial k}=\frac{\partial}{\partial k}(\ln(ka^k))=\frac{1}{ka^k}(a^k+k^2a^{k-1})=\frac 1k+\frac ka $$
Method 2:
$$ \frac{\partial f}{\partial k}=\frac{\partial}{\partial k}(\ln(ka^k))=\frac{\partial}{\partial k}(\ln(k)+k\ln a)=\frac 1k+\ln a $$
How come the result is not the same? Thanks a lot for explaining!
Method 1 : Let $f(x) = xa^x$ we have $$ f'(x) = a^x + x\frac{d}{dx}a^x = a^x + a^x \ln a$$ Hence if $g(x) = \ln (x)$ we have $$ g'(f(x)) = g'(f(x))f'(x) = \frac{a^x + a^x \ln a}{xa^x} = \frac{1}{x} + \ln a$$ You computed the derivative of $f(x) = xa^x$ incorrectly.