# Calculating Ricci tensor and Ricci scalar numerically

I am trying to calculate Ricci tensor numerically for arbitrary metric. I think my code looks okay and when I try to calculate the metric tensor of flat Minkowski space-time in Cartesian coordinate it gives zero Ricci tensor and Ricci scalar as it should for a flat space-time. Because of constant components of the metric tensor this is very trivial. But an equivalent description of the metric tensor in Spherical coordinates should give an identically zero Ricci tensor and scalar. However, my code does not give an identical zero answer. I tried to probe the situation in a bit more detail and I think the problem stems from the finite difference method of numerical differentiation and the non-linearity of the contravariant component of the metric tensor in Christopher symbol ($\Gamma^i_{jk}=\frac{1}{2}g^{il}(g_{jl,k}+g_{kl,j}-g_{jk,l})$. As the coordinates come close to the origin the finite difference method progressively fails because the function becomes more and more non-linear.

So my question is: How do I go about solving this situation? How do I deal with the problem of numerically differentiating a non-linear function to get the correct value for Ricci tensor and hence Ricci scalar.

I have tried both forward finite difference method and the central finite difference method but both these methods give the same inconsistencies for small values of the coordinates. One possible solution that I figure is to use variable grid spacing and asymptotically increase the number of points near the origin.

My real concern is that I don't have a way to check if my code is correct since I cant check the answer on a known case of Minkowski metric.

Update: I used non-uniform spacing and as expect it significantly reduced the errors in the Ricci tensor which is now zero upto 5 decimal places at least. I will however continue to look for better methods to differential non-linear functions numerically.

• Spherical polar coordinates have a coordinate singularity at the origin (the map from coordinate values to points on the manifold is not 1-1): things aren't going to work there. – tfb Jan 4 '17 at 9:25
• True and it makes a lot of sense but I am not calculating it AT the origin. However, things start to fall apart long before you reach the singularity. As I mention that the situation becomes non-linear as I come close to the origin. – Shaz Jan 4 '17 at 10:07
• Yes, things will become increasingly hard as you approach the coordinate singularity because the coordinates are getting less and less numerically good there. The solution is either to do some hairy numerical methods thing which I don't know about but numerical methods people will (I guess make all the steps much smaller and have many more of them?) or to have a chart of two coordinate patches so you never need to go near the singularity. – tfb Jan 4 '17 at 10:31
• Yeah. Whats really bothering me is that I dont have a way to check if my code is correct since I cant check it on a known case. Also, unfortunately, I cant think of any metric (other than Minkowski) which is linear so I can check my code and Minkowski is so trivial that it beats the purpose I think. – Shaz Jan 4 '17 at 10:45
• May I ask if there is a specific reason you want to evaluate them numerically, since they can very easily be computed symbolically? – JamalS Jan 4 '17 at 10:52