Post Reply 
(11C) X to Power of X Equation
02-15-2018, 09:58 PM (This post was last modified: 02-15-2018 11:19 PM by Dieter.)
Post: #3
RE: (11C) X to Power of X Equation
(02-15-2018 08:04 PM)Dieter Wrote:  I still am not quite satisfied with the initial guess. It can be improved so that one or two iterations can be saved. Also the proposed algorithm does not work for any X. Maybe someone else has a better idea.

Here is an improved version. It essentially calculates W(ln Y) and calculates the final result from this. The algorithm uses a third order Halley method as implemented in a thread in the old forum, cf. message #43. For ~10 digits it should converge within 5 iterations. BTW the WP34s Lambert W code is based on the versions in the linked thread.

Code:
LBL E
LN
STO 0
1
+
LN
ENTER
x>0?
LN
x<0?
CLX
-         // = first approximation
5
STO I     // loop counter: do not more than 5 iterations
R↓
LBL 2
ENTER     // fill stack with current approximation
ENTER
ENTER
RCL 0
X<>Y
e^x
/
-
X<>Y
1
+
/
LstX
1/x
1
+
X<>Y
x
LstX
X<>Y
2
/
CHS
1
+
/
-         // = new approximation
x=y?      // is it equal to the previous one?
GTO 3     // then quit
DSE I     // else decrement loop counter
GTO 2     // if less than 5 iterations are done do another loop
LBL 3     // exit routine
ST0/0     // calculate result via ln Y / W(ln Y)
e^x       // calculate result via e^W(ln Y)
RCL 0     // and return both of them on the stack
RTN

Since there may be a slight error in the last digit the program returns two values in X and Y that usually bracket the exact solution.

Example:

1000 [E] => 4,555535705
 [X<>Y]  => 4,555535705

3125 [E] => 5,000000001
 [X<>Y]  => 4,999999998

As far as I can tell the program should work well for input > 0,7. But try it yourself and see what you get.

BTW, if you remove the LN in the second step and replace everything after LBL 3 with a RTN you have a program that calculates Lambert's W function of x. Here the program works well down to approx –0,36. For input closer to –1/e the returned result becomes inaccurate. That's why the linked program in the old forum switches to a different method here.

Dieter

Edit: Take a look at message #61 in the linked thread. This leads to the following method for manually calculating the solution of xx=y:

Type y [ln] [ENTER] [ENTER] [ENTER]
Now repeat pressing [ln] [÷] until the desired accuracy is reached.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(11C) X to Power of X Equation - Gamo - 02-15-2018, 12:33 PM
RE: (11C) X to Power of X Equation - Dieter - 02-15-2018 09:58 PM
RE: (11C) X to Power of X Equation - Gamo - 02-16-2018, 06:36 AM
RE: (11C) X to Power of X Equation - Gamo - 02-19-2018, 01:00 AM
RE: (11C) X to Power of X Equation - Gamo - 02-20-2018, 01:49 AM
RE: (11C) X to Power of X Equation - Gamo - 02-20-2018, 09:28 AM
RE: (11C) X to Power of X Equation - Gamo - 02-21-2018, 04:25 AM



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