0

When running the below code with SymPy:

print("y1: ", TransY)
print("y2: ", TrigoY)
print(TransY.equals(TrigoY))
print(sp.simplify(TransY - TrigoY) == 0)
print(sp.simplify(TransY - TrigoY))

from looking at the output it seems TransY and TrigoY are equal. but the equality check, with simplify, shows otherwise:

y1:  0.707106781186547*L1 + 0.707106781186548*L2 + 0.258819045102521*L3
y2:  0.707106781186547*L1 + 0.707106781186548*L2 + 0.258819045102521*L3
False
False
-1.11022302462516e-16*L3

any advice?

Roy
  • 139
  • 3
  • 11
  • 1
    You're using floats and the float values are not precisely equal to their given precision. Sympy's `srepr` will give a more verbose representation of the expressions that should show the difference. – Oscar Benjamin Nov 18 '20 at 20:36
  • correct. can spot the difference in the L3 Multiplication. srepr(TrigoY) Out[3]: "Add(Mul(Float('0.70710678118654746', precision=53), Symbol('L1')), Mul(Float('0.70710678118654757', precision=53), Symbol('L2')), Mul(Float('0.25881904510252102', precision=53), Symbol('L3')))" srepr(TransY) Out[4]: "Add(Mul(Float('0.70710678118654746', precision=53), Symbol('L1')), Mul(Float('0.70710678118654757', precision=53), Symbol('L2')), Mul(Float('0.25881904510252091', precision=53), Symbol('L3')))" now thinking why is that and how to fix\avoid... – Roy Nov 18 '20 at 21:01
  • Oscar's hint helped to identify why. So used evalf(10) for 10 decimal digits precision which is sufficient. – Roy Nov 22 '20 at 11:42

0 Answers0