Increasing precision of numpy.dot (python) -
i'm attempting simulate physical system. in order propagate solutions need able multiply matrices of determinant = 1 describe each part of system. in code below t(variables) 2-dimensional matrix det(t) = 1, indicates region number , rest irrelevant.
when run code systems more 30 regions, final msys no longer has determinant = 1. checked value of determinant of msys throughout calculation , it's 1 first few iterations starts diverging that. i've tried putting dtype = float64 when creating array t see if improve precision , stop breaking down saw no improvement.
is there way write code avoid error accumulating or way can increase amount of decimal places numpy stores make error negligible systems 100+ regions.
for in range(n): if == 0: msys = t(l[i],i,k) else: msys = numpy.dot(t(l[i]-l[i-1],i,k), msys) return msys
all floating point operations have limited precision , errors accumulate. need decide how precision "good enough" or how error accumulation "negligible". if float64 not precise enough you, try float128. can find out precision of float types this:
in [83]: np.finfo(np.float32).eps out[83]: 1.1920929e-07 in [84]: np.finfo(np.float64).eps out[84]: 2.2204460492503131e-16 in [85]: np.finfo(np.float128).eps out[85]: 1.084202172485504434e-19
here lot more info floating point arithmetic: what every computer scientist should know floating-point arithmetic
Comments
Post a Comment