General Relativity/Metric tensor
From Wikibooks, the open-content textbooks collection
Recall that a tensor is a linear function which can convert vectors into scalars. Recall also that a distance can be stated as a formula that converts vectors to a scalar. So can we express distance with tensors formulas? Yes, we can.
The first problem comes in, in that tensors are linear functions, but we have some squares in our distance formula. We can deal with this with a mathematical trick. Consider the formula for distance in normal three dimensional Euclidean space using cartesian coordinates:

We can rewrite this as:

Now δij is obviously a tensor. What type of tensor is it? Well it takes two contravariant vectors and turns them into a scalar ds2. So it must be a covariant tensor of rank 2. δij is called the Kronecker delta tensor, which is 1 whenever i = j and 0 otherwise. In general, instead of components δij, we have gij :

This leads us to a general metric tensor gij. As shown earlier, in Euclidean 3-space,
is simply the the Kronecker delta matrix.
And that is the equation of distances in Euclidean three space in tensor notation.
Now let's do special relativity using this notation:

where the Greek letters just remind us that we are summing over four dimensional space time. Now in the case of special relativity gμν is zero for where μ and ν are different, +1 for the space indices 1,2,3 and − c2 for the time index. We can call this special matrix η, giving us the formulas:

In general, however, gij will not be a constant. A simple example where we can see that is spherical coordinates, with the metric

Here, x1 = r, x2 = θ, x3 = φ, g11 = 1, g22 = r2, g33 = r2sin2θ, and g12 = g13 = g23 = 0.
Also, a metric may have off-diagonal terms, as in

It is easy to see that g12 = 1 and g11 = g22 = 0.