Python: Complex Number Arithmetic and Lambert Function
07-14-2021, 04:17 PM (This post was last modified: 07-14-2021 05:27 PM by Albert Chan.)
Post: #2
 Albert Chan Senior Member Posts: 1,676 Joined: Jul 2018
RE: Python: Complex Number Arithmetic and Lambert Function
Newton's method with f(w) = w*e^w - z is not stable with bad guess.

A better setup is with f(w) = w + log(w/z), more stable and faster convergence.

>>> from mpmath import *
>>> z = 2+3j
>>> w = 1+1j # guess of W(z)
>>> for i in range(5): w -= (w-z*exp(-w)) / (w+1); print i+1, w
...
1 (0.925920455007468 + 0.525629062362773j)
2 (1.11168436157991 + 0.529383890736917j)
3 (1.09040865244656 + 0.530090770362652j)
4 (1.09007661082612 + 0.530139691067221j)
5 (1.09007653448579 + 0.530139720774835j)

>>> w = 1+1j # guess of W(z)
>>> for i in range(5): w -= (w+log(w/z))*w/(w+1); print i+1, w
...
1 (1.1220615411005 + 0.505617553600088j)
2 (1.09019950929821 + 0.530419495346751j)
3 (1.09007653522354 + 0.530139702926175j)
4 (1.09007653448579 + 0.530139720774839j)
5 (1.09007653448579 + 0.530139720774839j)
 « Next Oldest | Next Newest »

 Messages In This Thread Python: Complex Number Arithmetic and Lambert Function - Eddie W. Shore - 07-14-2021, 02:42 PM RE: Python: Complex Number Arithmetic and Lambert Function - Albert Chan - 07-14-2021 04:17 PM

User(s) browsing this thread: 1 Guest(s)