In Python 2.x, /
returns an integer value if both its operands are integers. As a special case, n/d
is 0 if n < d
and both are positive.
For
def exp_rule1 (mu1, h, alpha):
return h**2/(4*mu1**2)
you want to ensure that either the numerator or denominator is a floating point value. A simple way to do that is to make the 4
a float instead of an integer.
def exp_rule1 (mu1, h, alpha):
return h**2/(4.0*mu1**2)
Another solution is to import the new 3.x behavior for /
, which is to always return a float regardless of the operands. If you do this, replace any divisions where you rely on integer division with //
instead.
# This allows 1/2 to return 0.5 instead of 0
from __future__ import division