First, check that the equation you are using are correct. Do you get the right answer when you manually evaluate the equation?
If you think the equation is correct, try debugging it by breaking it...