Lambert W Function (hp-42s)
|
12-29-2022, 04:17 AM
(This post was last modified: 12-29-2022 09:08 PM by Albert Chan.)
Post: #51
|
|||
|
|||
RE: Lambert W Function (hp-42s)
I discovered a bug, for termination condition.
We used y' == y' + dy^2 termination test, but it is wrong Assuming Newton's method have quadratic convergence, it should be: 1 == 1 + (relative error)^2 1 == 1 + (dy/y')^2 y'^2 == y'^2 + dy^2 If y' is big, this does not matter, our test implied relative error test too. It may terminate later than needed, but that's OK. Problem is if we use this for e^W-1(-ε), which results in y' even smaller than ε Now, the flawed termination test quit early. Example, for ε = 1E-99: -1e-99 XEQ "eW" → W0(-ε) = 1. - - + * R/S → 2.201582623716450630677604534034768e-102 This quit too early (not even 1 correct digit!), we use this guess for next iteration: CLX + R/S → 4.281027759337267571527542476904921e-102 We now have 3 correct digits. It will take a few more iterations for convergence. We use this formula, which is very accurate close to x = -1/e e^W(x) ≈ 1/e + (x+1/e)/3 + sqrt ((2/e)*(x+1/e)) I am too lazy to code relative error test, and just hard coded right eps for the job. If y and y' matched 17 digits, this implied y' converged to 34 digits. Worse case, we have 17+ correct digits. Code: 00 { 59-Byte Prgm } With this updated eW, we get (all digits correct) e^W-1(-1E-99) = 4.284330166764374654650589938202028e-102 → W-1(-1E-99) = -233.4087152660372939791972288026527 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)