# How to transform a tensor (for example, the second order identity tensor) or matrix from cartesian coordinates to cylindrical coordinates?

First, I believe the unit tensor is a diagonal tensor with diagonal elements of 1, regardless of whether it is in Cartesian coordinates or cylindrical coordinates.

Then, I wanted to verify this using Mathematica. I transformed the unit tensor, Icar, from Cartesian coordinates to cylindrical coordinates to obtain Icyl.

However, I noticed that some components of Icyl are unexpectedly equal to 4.

Where did I make a mistake? It has been bothering me all day. Thank you.

Clear["Global*"] // Quiet;
cyl = {r, \[Theta], z};
car = CoordinateTransform["Cylindrical" -> "Cartesian", cyl];
Icar = IdentityMatrix[3];
Icyl = TensorContract[
dcardcyl\[TensorProduct]dcardcyl\[TensorProduct]Icar, {{1, 5}, {3,
6}}];
Icyl // Simplify
`

Its clear that you are computing the square of the Jacobian $$J_{ik}= \frac{\partial}{\partial y_i} x_k(y)$$ $$J_{ik} J_{kl} \delta_{lm}=J_{ik} J_{km}= \frac{\partial}{\partial y_i} x_k(y)\frac{\partial}{\partial y_k} x_l(y)$$ so you contract over an index pair in different bases.
But a basis transform contracts each index in the same way like a product of vectors $$J_{ia} J_{kb} \delta_{ab}=J_{ia} J_{ka} =(J J^T)_{ik}$$ $$J^T J = G$$ acts as the metric tensor on tangent vectors in the local basis. It is not the unit matrix by $$\left< u , J^T J v \right> = \left< J u , J v \right>$$.
Generally speaking, on an metric manifold, metric, unit tensor and inverse metric are the same object in different basis representations $$g_{ij} \left(g^{-1}\right) ^{jk} = \delta_i^k$$ can be interpreted as $$\delta$$ being the mixed representation of the metrics, or, vice versa, the metric is the covariant representation of the mixed unit tensor.