Added g function

Paul: I added the function which calculates g.