+ 2
Euler's formula in python
The great mathematician Euler discovered a fascinating mathematical formulaz according to which "e to the power of pi i is -1". [e^(πi)=-1] I tried to do this in python by the command pow(math.e, math.pi*1j) But the output isn't -1. Can anyone tell me how to do it the correct way? Thanks.
12 Antworten
+ 5
Check it out :)
https://code.sololearn.com/cx97bYh3wVIc/?ref=app
+ 7
Avish Excellent! 👌
+ 5
Avish check it out now. I added formatting to show that it is zero indeed. Or kind of :)
+ 4
but i is imaginary number...
+ 4
Python doesn't know or use the actual values of pi or e, that's why calculating with them will always lead to (negligible) errors
+ 2
The output is -1 + a very small number which you can assume it is 0 as this is a computer and not an actual mathematician (problem with computers and irrational numbers, long story)
+ 2
Kuba Siekierzyński I just found out a better way of doing it. Hope you like it.
https://code.sololearn.com/cVFrOVv5Tvw4/?ref=app
+ 1
Avish Kathpal I don't. In Python 1j means the square root of -1.
+ 1
Kuba Siekierzyński Thanks for you help.
0
Kuba Siekierzyński , why do you neglect the imaginary part?
0
At the end of the number you will see e-16 Which means 10^-16 which is a very small number
0
Kuba Siekierzyński Then have you written .real() there? It is used to just print the real part and not the imaginary part.