HP49-50G Lambert function
10-19-2020, 09:06 AM
Post: #3
 Gil Senior Member Posts: 379 Joined: Oct 2019
RE: HP49-50G Lambert function W(z)
Lamber function for HP49-50G
W.Z=>X

Version 2.
- That version allows now complex numbers Z as argument (and will give a complex number as answer.

- Having the Z complex number,
find the complex solution small z,
such that (...z) × EXP (...z) = Z.

- The program allows also, as argument, negative numbers < -1/e, in which case the answer will also be a complex number z.

- For the other cases, when entering
Y W(Z) ENTER,
we get the searched real value x=W(Y).

- The program gives almost instantaneous answer,
but do no tamper on previously registered variable.

- Here is the new program code:
« "Lambert W(Z):
Having result Y
Y real in (-879.3 infinity)
or Z complex (a,b)
W(Z) finds / gives X
such that
(X * EXP X) = Z
W(X * EXP X) =X

" DROP =>Y
«
IF Y TYPE 1. == NOT
THEN
IF Y -1. EXP NEG <
THEN Y 0. RC 'Y' STO
END
END
IFERR 'X' 'X' RCL
THEN
ELSE
END
IF Y TYPE 1. ==
THEN DUP2 SAME NOT
IF
THEN 'X' PURGE
END 'a*EXP(a)*COS(b)-b*EXP(a)*SIN(b)' Y OBJ DROP = 'a*EXP(a)*SIN(b)+b*EXP(a)*COS(b)' Y CR SWAP DROP = 2. ARRY 'a' 'b' 2. ARRY [ 1. 1. ] MSLV OBJ DROP RC UNROT DROP2
ELSE 'X*EXP(X)-Y' 'X' 1. ROOT
END UNROT DUP2 SAME
IF
THEN DROP2 'X' PURGE
ELSE SWAP STO
END "W(" Y + ")" + =>TAG
»
»
Example of use:

What is the Lambert x value for y=(sqrt 2) /2?
1) 2 SQRT 2 / gives. 707
2) 2 SQRT 2 / W.Y=>X gives 0.4506

Application:

Solve x^2*e^x=2

Take square root of the above expression:
x*e^(x/2) = sqrt 2

Divide by 2:
(x/2)*e^(x/2) = (sqrt 2) / 2

That has a form of:
"(X..X)" * e ^"(X..X) " = (sqrt 2)/2

Then W ["(X..X)" * e ^"(X..X)"] = W [(sqrt 2)/2]
Or "X.. X" = W [(sqrt 2)/2]

In our case we have:
W[(x/2)*e^(x/2)] = W[(sqrt 2) / 2]
Or x/2 = W[(sqrt 2) / 2]
Or x = 2 * W[(sqrt 2) / 2] = 2 * 0.4506 = 0.9012

Remarks welcome.

Regards,
Gil Campart

Attached File(s)