# What is going wrong in my calculation of metric tensor for cylindrical coordinates?

I am playing around with calculating a line element for cylindrical coordinates. So I tried this in two different ways.

First, I took the position vector to be $$\vec{r} = (x^2+y^2)^{\frac{1}{2}}\hat{r} + tan^{-1}(\frac{y}{x})\hat{\phi} + z\hat{z}.$$

Then, I took the position vector to be $$\vec{r} = rcos\phi \hat{x} + rsin\phi \hat{y} + z\hat{z}.$$

For both of these processes, I used $$e_u = \frac{\partial \vec{r}}{\partial u}$$ to construct the basis vectors where in the first case, $$u = x,y,z$$ and in the second case, $$u=r,\phi ,z$$. However, when I go to construct the line element by taking the respective dot products of these basis vectors, I do not get the same result. Since the line element must be invariant, I believe I should get metrics that at least have the same diagonal elements, but in this method, only the position vector $$r = rcos\phi \hat{x} + rsin\phi \hat{y} + z\hat{z}$$ provides the proper diagonal elements on the metric. For the other position vector, $$\frac{\partial \vec{r}}{\partial r}$$ dotted with itself is not one. What is going wrong here?

The error is with the $$\phi\hat{\phi}$$ term. The position vector in cylindrical/spherical coordinates is NOT $$\vec{r}=r\hat{r}+\phi\hat{\phi}+z\hat{z}$$! This is obvious once you write down the definition of $$\hat{r},\hat{\phi},\hat{z}$$ in terms of $$\hat{x},\hat{y},\hat{z}$$. For example, \begin{align} \hat{r}=\frac{x\hat{x}+y\hat{y}}{r}. \end{align} So, \begin{align} \vec{r}:=x\hat{x}+y\hat{y}+z\hat{z}=r\hat{r}+z\hat{z}. \end{align}
To reiterate: just because $$\vec{r}=\sum_{i=1}^3x^ie_i$$ is the definition of the position vector in cartesian coordinates, it DOES NOT mean that if you consider some other coordinate system $$(\xi^1,\xi^2,\xi^3)$$, with corresponding unit vectors $$\{e_{\xi,1},e_{\xi,2},e_{\xi,3}\}$$ (the precise definition being $$e_{\xi,i}$$ being the normalized version of the tangent vector field $$\frac{\partial}{\partial \xi^i}$$), then the position vector is $$\vec{r}=\sum_{i=1}^3\xi^i\,e_{\xi,i}$$.