Today I'm trying to prove the Euler's identity which is $e^{i\pi}+1=0$ by Python. My code is as follows:
euler = math.e
pi = np.pi
cos_pi = np.cos(pi)
sin_pi = np.sin(pi)
euler_id = euler*(imaginarypi)
print((cos_pi+imaginarysin_pi)+1)
print('e^(ipi): %s' %eulers_id) # output = (-1+1.2246467991473532e-16j)
print('e^(i*pi)+1 =: %s' %(eulers_id+1)) # output = 1.2246467991473532e-16j
What I get is an imaginary number, did I do something wrong here? Thank you for your answer.
1.2246467991473532e-16makes the result a very small imaginary that "should be" zero. You're simply encountering an implementation issue with inexact floating-point arithmetic. – Blue Jul 31 '22 at 14:23