[HP41] Lambert function RPN; question
|
12-27-2022, 02:31 AM
(This post was last modified: 12-27-2022 02:43 AM by Thomas Klemm.)
Post: #7
|
|||
|
|||
RE: [HP41] Lambert function RPN; question
(12-26-2022 02:07 PM)Didier Lachieze Wrote: Here is the original discussion from where this program is originated : Help solving equation. It took me a while to figure out that I had used Halley's method with: \( \begin{align} f(x) &= x e^x - a \\ f'(x) &= (1 + x) e^x \\ f''(x) &= (2 + x) e^x \\ \end{align} \) This is the formula used in the program: \( \begin{align} x_{{n+1}} &=x_{n}-{\frac {f(x_{n})}{f'(x_{n})-{\frac {f(x_{n})}{f'(x_{n})}}{\frac {f''(x_{n})}{2}}}} \\ \\ &=x_{n}-{\frac{x e^x - a}{(1 + x) e^x-\frac{(x e^x - a)(2 + x) e^x}{2(1 + x) e^x}}} \\ \\ &=x_{n}-{\frac{x e^x - a}{(1 + x) e^x-\frac{(x e^x - a)(2 + x)}{2(1 + x)}}} \\ \\ &=x_{n}-{\frac{x e^x - a}{(1 + x) e^x-\frac{(x e^x - a)(1 + \frac{1}{1 + x})}{2}}} \\ \end{align} \) But we could also use: \( \begin{align} x_{n+1} &=x_{n}-{\frac {f(x_{n})}{f'(x_{n})}}\left[1-{\frac {f(x_{n})}{f'(x_{n})}}\cdot \frac {f''(x_{n})}{2f'(x_{n})}\right]^{-1} \\ \\ &=x_{n}-{\frac {x e^x - a}{(1 + x) e^x}}\left[1-{\frac {x e^x - a}{(1 + x) e^x}}\cdot \frac {(2 + x) e^x}{2(1 + x) e^x}\right]^{-1} \\ \\ &=x_{n}+{\frac {a - x e^x}{e^x + x e^x}}\left[1+{\frac {a - x e^x}{e^x + x e^x}}\cdot \frac {2 + x}{2 + 2x}\right]^{-1} \\ \end{align} \) We end up with a slightly shorter program, here for the HP-42S: Code: 00 { 41-Byte Prgm } But it should work for the HP-41C as well. Example 4 XEQ "W" 1.20216787320 So why Halley and not Newton, you might ask. With a little more effort, we get cubic convergence, which is nice. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)