What's that? You got an error even though the function worked for d = 1.2?

Perhaps you forgot that functions should work for vectors as well as scalars whenever possible. That means using array operators in the function for multiplication (.*), division (./) and exponentiation (.^).

And not just expressions involving d. Any one of the parameters could be an array and the function should work. The only genuinely scalar value is g.