I am trying to derivate divergence in cylindrical coordinates, following is my derivation which is wrong and different from text book. I am confused why the derivation is wrong.
Denote $\nabla_x=(\partial_{x_1},\partial_{x_2},\partial_{x_3}) $ , $\nabla=(\partial_{r},\partial_{\theta},\partial_{z}) $, $u(x_1,x_2,x_3)=(u_1(x_1,x_2,x_3),u_2(x_1,x_2,x_3),u_3(x_1,x_2,x_3))=u^re_r+u^{\theta}e_{\theta}+u^ze_z$ is a vector field, where $(x_1, x_2, x_3)$ is the Cartesian coordinates and $(r, \theta, z)$ is cylindrical coordinates. The gradient operator can be written as follows $$\nabla_x =(\cos(\theta)\cdot\partial_r-r^{-1}\sin(\theta)\cdot\partial_{\theta}, \sin(\theta)\cdot\partial_r+r^{-1}\cos(\theta)\cdot\partial_{\theta},\partial_z)$$ and $u$ can be written as $$u=(\cos(\theta)u^r+\sin(\theta)u^{\theta}, -\sin(\theta)u^r+\cos(\theta)u^{\theta},u^z)$$ Thus, we make dot product of them and only need to observe the coefficient of $\partial_r u^r$ we will know this derivation is wrong: $$\nabla_x\cdot u=[\cos^2(\theta)-\sin^2(\theta)]\partial_r u^r+....$$ but why?
The correct transformation rules are: \begin{align} \partial_x&=\cos\theta\,\partial_r-\tfrac1r\sin\theta\,\partial_\theta\,,\\[2mm] \partial_y&=\sin\theta\,\partial_r+\tfrac1r\cos\theta\,\partial_\theta\,,\\[2mm] u^x&=\cos\theta\,u^r-r\sin\theta\,u^\theta\,,\\[2mm] u^y&=\sin\theta\,u^r+r\cos\theta\,u^\theta\,. \end{align} You should take them and check that the vector field is coordinate independent: $$ u^x\partial_x+u^y\partial_y+u^z\partial_z=u^r\partial_r+u^\theta\partial_\theta+u^z\partial_z\,. $$ Then, \begin{align}\require{cancel} \partial_xu^x&=\big(\cos\theta\,\partial_r-\tfrac1r\sin\theta\,\partial_\theta\big)\big(\cos\theta\,u^r-r\sin\theta\,u^\theta\big)\\ &=\cos^2\partial_ru^r-\cancel{\cos\theta\sin\theta\,u^\theta}+\tfrac1r\sin^2\theta\, u^r-\bcancel{\tfrac1r\sin\theta\cos\theta\,\partial_\theta u^r}+\cancel{\sin\theta\cos\theta\,u^\theta}\\&\quad+\sin^2\theta\,\partial_\theta\,u^\theta\,,\\[2mm] \partial_yu^y&=\big(\sin\theta\,\partial_r+\tfrac1r\cos\theta\,\partial_\theta\big)\big(\sin\theta\,u^r+r\cos\theta\,u^\theta\big)\\[2mm] &=\sin^2\theta\,\partial_ru^r+\cancel{\sin\theta\cos\theta\,u^\theta}+\tfrac1r\cos^2\theta\, u^r+\bcancel{\tfrac1r\cos\theta\sin\theta\,\partial_\theta u^r}-\cancel{\cos\theta\sin\theta\,u^\theta}\\&\quad+\cos^2\theta\,\partial_\theta u^\theta\,. \end{align} The divergence is therefore \begin{align} \partial_xu^x+\partial_yu^y+\partial_zu^z&=\partial_ru^r+\tfrac1ru^r+\partial_\theta u^\theta+\partial_zu^z\,. \end{align} It is a popular convention to use the orthonormal basis $\{\partial_r,\tfrac1r\partial_\theta,\partial_z\}$ instead of the coordinate basis $\{\partial_r,\partial_\theta,\partial_z\}\,.$ In the orthonormal basis the vector field has obviously the $\theta$-component $u_{on}^\theta=ru^\theta$ while the other two do not change. The divergence can then be written as $$ \partial_xu^x+\partial_yu^y+\partial_zu^z=\tfrac1r\partial_r(ru^r)+\tfrac1r\partial_\theta u_{on}^\theta+\partial_zu^z\,. $$ To address your comment: Popular notations for the normalized basis vector fields are \begin{align} \boldsymbol{\hat{x}}&=\boldsymbol{e}_x=\partial_x\,,&\boldsymbol{\hat{y}}&=\boldsymbol{e}_y=\partial_y\,,\\ \boldsymbol{\hat{r}}&=\boldsymbol{e}_r=\partial_r\,,&\boldsymbol{\hat{\theta}}&=\boldsymbol{e}_\theta=\tfrac1r\partial_\theta\,,\\ \end{align} (let's ignore the trivial $z$-coordinate). When you invert my first two transformation rules you get in this notation \begin{align} \boldsymbol{e}_r&=\cos\theta\,\boldsymbol{e}_x+\sin\theta\,\boldsymbol{e}_y\,,\\ \boldsymbol{e}_\theta&=-\sin\theta\,\boldsymbol{e}_x+\cos\theta\,\boldsymbol{e}_y\,. \end{align} In components this is exactly what you have learned.
My advice:
Know if you are using normalized or unnormalized basis vector fields.
Try the partial derivatives notation and the unnormalized coordinate basis $\{\partial_r,\partial_\theta\}$ because you will be able to derive every coordinate transformation rule simply from the chain rule without remembering anything.