I have the following program:
def eigen(a, b, c, d, e, f):
epsilon = 1E-9
a = abs(float(a*e+b*f)/float(c*e+d*f) - float(e)/float(f))
print a, epsilon
print a < epsilon
print abs((a*e+b*f)/float(c*e+d*f) - e/float(f)) < epsilon
Prints:
0.0 1e-09
True
False
when the values of a,b,c,...,f = 3, 1, 1, 3, 4, -4
I expected the last two lines to both print True as I thought they were equivelent statements. Will you kindly explain to me what is going on?
Thank you for your time.
Kind regards,
Marius
The problem is that
a = abs(float(a*e+b*f)/float(c*e+d*f) - float(e)/float(f))
assigns a different value to a, which messes up the calculation that follows:
print abs((a*e+b*f)/float(c*e+d*f) - e/float(f)) < epsilon
# ^ This is no longer the original a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With