Python3: exponents and logarithms
math.exp() doesn't work for complex numbers:
>>> math.exp (math.pi*1j)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert complex to float
This doesn't hurt me much, as ** works as intended:
>>> math.e ** (math.pi*1j)
(-1+1.2246467991473532e-16j)
Now the problem is with logarithms. math.log doesn't work for negative
numbers:
>>> math.log(-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: math domain error
(Expected result: (0+3.141592653589793j))
How can I calculate a logarithm in python whose result is complex?
(Preferably without implementing it myself)
No comments:
Post a Comment