But when I insert the values for q and z through variables the formula returns NaN (not a number), which is strange because the formula as I've put into C2 should consist only of numbers. Even when I manually change all z's and q's to numbers the outcome stays NaN.

So I might just have put in the formulas the wrong way, or I'm pushing C2 beyond it's limits.

Yeah with a quick look over the main thing you missed was adding a "-" inside the sqrt. Without it you're calculating the sqrt of a negative number which is NAN. I can look over it better tomorrow.