Post Reply 
Lambert W Function (hp-42s)
10-03-2020, 04:31 PM (This post was last modified: 12-30-2022 10:41 PM by Albert Chan.)
Post: #41
RE: Lambert W Function (hp-42s)
We were testing special case x = -r = -1/e
I was curious, is it the same as guess(x) = -x ?

guess(x) = r + 0.3*(x+r) + √(2r*(x+r)) = -x   → √(2r*(x+r)) = -1.3*(x+r)

Let z = x+r, we have √(2/e*z) = -1.3*z           → z = 0 → x = -r

With this, we can simplify the code greatly, moving the test after guess(x).
And, turning repeat until loop into while do loop, remove the test altogether !

Bonus: now it checked both special case, x = -1/e, -1/e + 0j Smile

Code:
00 { 56-Byte Prgm }
01▶LBL "eW"
02 -1
03 E↑X          # r     x
04 ENTER
05 RCL+ ST Z    # x+r   r       x
06 ENTER
07 STO+ ST X    # 2x+2r x+r     r   x
08 RCL× ST Z
09 SQRT         # sqrt  x+r     r   x
10 STO+ ST Z
11 R↓           # x+r   sqrt+r  x   sqrt
12 0.3
13 ×
14 +            # y     x       x   x
15 X<>Y
16 +/-
17 X<>Y         # y     -x      x   x
18▶LBL 01
19 X=Y?         # Convergence check
20 RTN
21 STO ST Y
22 LN
23 1
24 +
25 R↑           
26 RCL+ ST Z
27 X<>Y         
28 ÷            # Newton-Raphson method
29 -            
30 STO× ST X    
31 LASTX        
32 STO+ ST Y    # y'    y'+dy^2 x   x
33 GTO 01
34 END

UPDATE:
There is a flaw in termination test.
I keep this for historical record. Please use corrected version
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Lambert W Function (hp-42s) - Juan14 - 05-16-2020, 04:07 PM
RE: Lambert W Function (hp-42s) - Werner - 05-17-2020, 07:56 AM
RE: Lambert W Function (hp-42s) - Werner - 05-17-2020, 08:15 AM
RE: Lambert W Function (hp-42s) - Gerald H - 05-17-2020, 09:29 AM
RE: Lambert W Function (hp-42s) - Werner - 05-18-2020, 08:04 AM
RE: Lambert W Function (hp-42s) - Juan14 - 05-17-2020, 12:12 PM
RE: Lambert W Function (hp-42s) - Juan14 - 05-18-2020, 10:51 PM
RE: Lambert W Function (hp-42s) - Juan14 - 05-21-2020, 12:09 AM
RE: Lambert W Function (hp-42s) - Werner - 05-22-2020, 11:39 AM
RE: Lambert W Function (hp-42s) - Werner - 05-23-2020, 04:20 AM
RE: Lambert W Function (hp-42s) - Werner - 06-11-2020, 05:17 AM
RE: Lambert W Function (hp-42s) - Werner - 06-11-2020, 09:20 AM
RE: Lambert W Function (hp-42s) - lyuka - 09-28-2020, 04:06 PM
RE: Lambert W Function (hp-42s) - Werner - 09-30-2020, 09:12 AM
RE: Lambert W Function (hp-42s) - Werner - 10-02-2020, 03:02 PM
RE: Lambert W Function (hp-42s) - Werner - 09-30-2020, 07:08 AM
RE: Lambert W Function (hp-42s) - lyuka - 09-29-2020, 09:21 AM
RE: Lambert W Function (hp-42s) - lyuka - 09-29-2020, 11:17 PM
RE: Lambert W Function (hp-42s) - lyuka - 09-30-2020, 11:04 AM
RE: Lambert W Function (hp-42s) - lyuka - 09-30-2020, 07:16 PM
RE: Lambert W Function (hp-42s) - Werner - 10-01-2020, 09:37 AM
RE: Lambert W Function (hp-42s) - Werner - 10-01-2020, 01:39 PM
RE: Lambert W Function (hp-42s) - lyuka - 10-01-2020, 06:25 PM
RE: Lambert W Function (hp-42s) - lyuka - 10-02-2020, 05:44 AM
RE: Lambert W Function (hp-42s) - Albert Chan - 10-03-2020 04:31 PM
RE: Lambert W Function (hp-42s) - lyuka - 10-03-2020, 07:56 PM
RE: Lambert W Function (hp-42s) - Werner - 10-05-2020, 08:03 AM
RE: Lambert W Function (hp-42s) - lyuka - 10-05-2020, 06:09 PM
RE: Lambert W Function (hp-42s) - Werner - 10-06-2020, 06:16 AM
RE: Lambert W Function (hp-42s) - lyuka - 11-09-2020, 08:30 AM



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