Post Reply 
lambertw, all branches
01-28-2024, 11:18 PM (This post was last modified: 01-29-2024 01:25 AM by Albert Chan.)
Post: #55
RE: lambertw, all branches
[Image: 435px-Mplwp_lambert_W_branches.svg.png]

Note that W curve is only in 1st and 3rd quadrant.
If x is in ℝ (implied a in ℝ too), they have same sign, then ln(x/a) = ln(|x|) - ln(|a|)

This give me an idea!

Code:
def LN(x, bad=-s*pi):
    x = ln(x)
    return conj(x) if im(x)==bad else x

My Python code used customized LN, to track signed zero, to give correct imag parts.
Example, to simulate ln(-1-0*I), set s=-1 --> LN(-1) = conj(pi*j) = -pi*j

But, what if re(a) were never negative to begin with?
Then, LN is not needed! Unlike ±pi, ±0 are numerically the same thing!

Let s = -1 if re(a)<0 else 1

x * e^x = a
(s*x) * e^x = s*a
ln(s*x) + x = ln(s*a) = B

p2> f = lambda x: show(x) + ln(s*x) - B
p2> df = lambda x: 1 + 1/x
p2> def show(x): print nstr(x, n=10); return x
...
p2> a = mpc(-0.1)
p2> s = -1 if re(a)<0 else 1
p2> B = ln(s*a)

p2> W(a, -1)
(-3.5771520639573 + 0.0j)
p2> findroot(f, x0=B, df=df, solver='newton')
(-2.302585093 + 0.0j)
(-3.776907719 + 0.0j)
(-3.579124176 + 0.0j)
(-3.577152275 + 0.0j)
(-3.577152064 + 0.0j)
(-3.577152064 + 0.0j)
(-3.5771520639573 + 0.0j)

This is nothing special, iterations are exactly the same as W code.
But let's try a *bad* guess, x0=B+j, crossed discontinuity!
(this guess for for W(a,-1) would get stuck in endless loops.)

p2> findroot(f, x0=B+j, df=df, solver='newton')
(-2.302585093 + 1.0j)
(-3.44870968 - 0.2167163462j)
(-3.575061443 + 0.002993043143j)
(-3.577151814 - 6.790747928e-7j)
(-3.577152064 + 1.841873128e-14j)
(-3.577152064 - 4.31950186e-29j)
(-3.577152064 + 0.0j)
(-3.5771520639573 + 0.0j)

We can use better solver, without worrying about over-shooting!

p2> findroot(f, x0=B, df=df, solver='halley')
(-2.302585093 + 0.0j)
(-3.48604165 + 0.0j)
(-3.577141461 + 0.0j)
(-3.577152064 + 0.0j)
(-3.577152064 + 0.0j)
(-3.5771520639573 + 0.0j)

p2> findroot(f, x0=B+j, df=df, solver='halley')
(-2.302585093 + 1.0j)
(-3.730387658 - 0.002761341752j)
(-3.577193828 - 2.173902656e-6j)
(-3.577152064 - 1.483011857e-16j)
(-3.577152064 - 2.350988702e-38j)
(-3.577152064 + 0.0j)
(-3.5771520639573 + 0.0j)

Comment:

What we really wanted is s = -1 if re(x)<0 else 1
This keep |arg(s*x)| closer to 0 then pi.

It happens that if final x is real, sign(x) = sign(a)
Unfortunately, for complex a, we don't know what s is ...
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
lambertw, all branches - Albert Chan - 04-07-2023, 01:24 PM
RE: lambertw, all branches - Albert Chan - 04-07-2023, 02:47 PM
RE: lambertw, all branches - Albert Chan - 04-19-2023, 01:30 AM
RE: lambertw, all branches - pier4r - 04-07-2023, 06:04 PM
RE: lambertw, all branches - Albert Chan - 04-07-2023, 07:54 PM
RE: lambertw, all branches - Albert Chan - 04-08-2023, 03:21 PM
RE: lambertw, all branches - Albert Chan - 04-08-2023, 05:54 PM
RE: lambertw, all branches - Albert Chan - 04-07-2023, 08:40 PM
RE: lambertw, all branches - Albert Chan - 04-09-2023, 03:59 AM
RE: lambertw, all branches - Albert Chan - 04-09-2023, 04:36 PM
RE: lambertw, all branches - Albert Chan - 04-10-2023, 04:44 PM
RE: lambertw, all branches - Albert Chan - 04-10-2023, 06:47 PM
RE: lambertw, all branches - Albert Chan - 04-13-2023, 03:03 PM
RE: lambertw, all branches - floppy - 04-13-2023, 04:14 PM
RE: lambertw, all branches - Albert Chan - 04-23-2023, 02:49 PM
RE: lambertw, all branches - Albert Chan - 04-23-2023, 04:40 PM
RE: lambertw, all branches - Albert Chan - 01-19-2024, 04:14 PM
RE: lambertw, all branches - Albert Chan - 01-20-2024, 04:48 PM
RE: lambertw, all branches - Gil - 01-20-2024, 10:52 PM
RE: lambertw, all branches - Albert Chan - 01-21-2024, 01:14 AM
RE: lambertw, all branches - Albert Chan - 01-21-2024, 01:54 AM
RE: lambertw, all branches - Gil - 01-21-2024, 01:53 PM
RE: lambertw, all branches - Albert Chan - 01-21-2024, 04:19 PM
RE: lambertw, all branches - Gil - 01-21-2024, 04:35 PM
RE: lambertw, all branches - Albert Chan - 01-21-2024, 06:03 PM
RE: lambertw, all branches - Albert Chan - 01-21-2024, 07:01 PM
RE: lambertw, all branches - Gil - 01-21-2024, 07:30 PM
RE: lambertw, all branches - Gil - 01-21-2024, 08:39 PM
RE: lambertw, all branches - Albert Chan - 01-21-2024, 10:06 PM
RE: lambertw, all branches - Gil - 01-21-2024, 09:51 PM
RE: lambertw, all branches - Gil - 01-21-2024, 10:56 PM
RE: lambertw, all branches - Albert Chan - 01-22-2024, 01:34 AM
RE: lambertw, all branches - Gil - 01-21-2024, 11:15 PM
RE: lambertw, all branches - Gil - 01-22-2024, 06:09 PM
RE: lambertw, all branches - Albert Chan - 01-22-2024, 07:29 PM
RE: lambertw, all branches - Gil - 01-22-2024, 11:33 PM
RE: lambertw, all branches - Albert Chan - 01-23-2024, 02:32 AM
RE: lambertw, all branches - Gil - 01-23-2024, 02:35 PM
RE: lambertw, all branches - Albert Chan - 01-23-2024, 03:54 PM
RE: lambertw, all branches - Gil - 01-23-2024, 04:57 PM
RE: lambertw, all branches - Albert Chan - 01-23-2024, 06:17 PM
RE: lambertw, all branches - Gil - 01-23-2024, 06:44 PM
RE: lambertw, all branches - Gil - 01-23-2024, 11:00 PM
RE: lambertw, all branches - Gil - 01-24-2024, 03:18 PM
RE: lambertw, all branches - Albert Chan - 01-24-2024, 08:53 PM
RE: lambertw, all branches - Gil - 01-25-2024, 12:37 AM
RE: lambertw, all branches - Gil - 01-25-2024, 01:10 AM
RE: lambertw, all branches - Gil - 01-25-2024, 03:04 AM
RE: lambertw, all branches - Albert Chan - 01-25-2024, 07:02 AM
RE: lambertw, all branches - Gil - 01-25-2024, 10:09 AM
RE: lambertw, all branches - Albert Chan - 01-25-2024, 04:13 PM
RE: lambertw, all branches - Gil - 01-25-2024, 05:14 PM
RE: lambertw, all branches - Albert Chan - 01-25-2024, 05:57 PM
RE: lambertw, all branches - Gil - 01-25-2024, 06:19 PM
RE: lambertw, all branches - Albert Chan - 01-28-2024 11:18 PM
RE: lambertw, all branches - Albert Chan - 02-01-2024, 02:17 AM
RE: lambertw, all branches - Albert Chan - 02-01-2024, 04:16 PM
RE: lambertw, all branches - Albert Chan - 02-02-2024, 11:49 AM



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