Update gravity.R

Changed calculation from a for loop to matrix operations. Confirmed that they give same result.