Post Reply 
(11C) X to Power of X Equation
02-15-2018, 12:33 PM (This post was last modified: 04-16-2018 12:43 PM by Gamo.)
Post: #1
(11C) X to Power of X Equation
Here is the approximation of the equation of X^X=Y
X to the power of X for the given Y

Procedure: Used FIX 6 or more, Store approximation value in R1 (STO 1)

Example: X^X=1000
Use 4 to store approximation value 4 [STO 1] then 1000 f [A] result 4.555536...

To check for answer: with answer already on display press [ENTER] [Y^X]

Program:
Code:

LBL A
LN
ENTER
ENTER
ENTER
RCL 1
LN
/
RCL 1
+
2
/
STO 1
.
0
1
2
STO I
CLx
+
LBL 1
LN
/
RCL 1
+
2
/
STO 1
ISG
GTO 1
RTN

Gamo
Find all posts by this user
Quote this message in a reply
02-15-2018, 08:04 PM (This post was last modified: 02-15-2018 08:21 PM by Dieter.)
Post: #2
RE: (11C) X to Power of X Equation
(02-15-2018 12:33 PM)Gamo Wrote:  Here is the approximation of the equation of X^X=Y
X to the power of X for the given Y

There is a closed form solution for this: X = eW(ln Y).
Here W is the Lambert W function, for instance featured on the WP34s.

(02-15-2018 12:33 PM)Gamo Wrote:  Program:
...

Gamo, this program will not work. When it passes LBL 1 for the first time the X-value is 0,01201 so that the program continues with the log of this counter value. It looks like a CLX + between STO I and LBL 1 might work – try it.

Also the program does essentially the same in the first steps and then during the iteration loop. Finally the 0,01201 can simply be replaced with ,012. Or, even better, initialize the counter with 12 and use DSE instead of ISZ.

(02-15-2018 12:33 PM)Gamo Wrote:  To check for answer [STO] answer then [ENTER] [RCL] [Y^X]

Simply type [ENTER] [yx]. ;-)

Here is a version that calculates an initial guess and then uses your approximation method. Press [R/S] to see the iteration converge. You may use [X<>Y] to compare the last and current approximation.

Code:
LBL A
LN
STO 0
1
+
LN
ENTER
LN
x<0?
CLX
-
e^x
LBL 1
R/S
ENTER
ENTER
ENTER
RCL 0
X<>Y
LN
/
+
2
/
GTO 1

Example (assuming FIX 6 mode):

1000 [A]  3,824155
[R/S]  4,487028
[R/S]  4,544273
[R/S]  4,553629
[R/S]  4,555211
[R/S]  4,555480
[R/S]  4,555526
[R/S]  4,555534
[R/S]  4,555535
[R/S]  4,555536
[R/S]  4,555536

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.

Dieter
Find all posts by this user
Quote this message in a reply
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
02-16-2018, 06:36 AM (This post was last modified: 02-16-2018 09:35 AM by Gamo.)
Post: #4
RE: (11C) X to Power of X Equation
Thank You Dieter

Very interesting topic in the old forum link and your program is also very good to give more variety of approximation.

I did update my program to add [CLx] [+] as you recommended and now work perfectly.

Gamo
Find all posts by this user
Quote this message in a reply
02-18-2018, 08:02 PM (This post was last modified: 02-19-2018 08:31 AM by Dieter.)
Post: #5
RE: (11C) X to Power of X Equation
(02-16-2018 06:36 AM)Gamo Wrote:  I did update my program to add [CLx] [+] as you recommended and now work perfectly.

Fine. I just posted a new version in the respective 12C thread. Since it's a nice and compact program, here it is for the 11C:

Code:
LBL E
LN
STO 0
,
7
3
y^x
1
+
5
STO 1
LBL 1
R↓
ENTER
ENTER
LN
x
1
STO-1
LstX
+
X<>Y
RCL 0
-
X<>Y
/
-
X<>Y
Δ%
EEX
7
x
INT
RCL 1
x
x≠0?
GTO 1
+
RTN

For more details cf. the linked 12C thread.

Dieter

Edit: just noticed that two ENTERs will do. ;-)
Find all posts by this user
Quote this message in a reply
02-19-2018, 01:00 AM (This post was last modified: 02-19-2018 01:24 AM by Gamo.)
Post: #6
RE: (11C) X to Power of X Equation
I like to try the Newton Method program that provided in the 11C Owner's Handbook with this X to the X power equation.
What is the program steps use to solve this X^X=1000 change equation to X^X - 1000=0

Example in the Handbook: f(x)=X^6 - X - 1 = 0
Steps: [STO 5] [6] [Y^X] [RCL] [5] [-] [1] [-]

Gamo
Find all posts by this user
Quote this message in a reply
02-19-2018, 08:15 AM (This post was last modified: 02-19-2018 09:00 AM by Dieter.)
Post: #7
RE: (11C) X to Power of X Equation
(02-19-2018 01:00 AM)Gamo Wrote:  I like to try the Newton Method program that provided in the 11C Owner's Handbook with this X to the X power equation.
What is the program steps use to solve this X^X=1000 change equation to X^X - 1000=0

Gamo, what keys would you press if you have a number in X and you now want to calculate X^X–1000? I think you know that.

[ENTER] [y^x] [EEX] 3 [–]

You can also replace the EEX 3 with, say, RCL 5 (assuming this is not used by the program) and store 1000 or any other number in R5.
This way you can solve for any Y without having to change the program:

[ENTER] [y^x] [RCL] 5 [–]

1000  [STO] 5
(run the program) => 4,5555...

4711  [STO] 5
(run the program) => 5,1563...

EEX 9  [STO] 5
(run the program) => 9,2950...

Dieter
Find all posts by this user
Quote this message in a reply
02-20-2018, 01:49 AM (This post was last modified: 02-20-2018 07:45 AM by Gamo.)
Post: #8
RE: (11C) X to Power of X Equation
According to the 11C Owner's Handbook to used the Newton's Method program.

The user must define the function f(x) by entering into program memory the keystrokes require to find f(x), assuming x is in the X-register. The main program requires register 0-4.

The equation is X^X-1000=0

Program step:

STO 5
RCL 5
Y^X
EEX
3
-

This steps work on the smaller number size because according to the book state that sometime the loop is too much then must change the loop count lower to successfully converge.

Gamo
Find all posts by this user
Quote this message in a reply
02-20-2018, 08:07 AM
Post: #9
RE: (11C) X to Power of X Equation
(02-20-2018 01:49 AM)Gamo Wrote:  Program step:

STO 5
RCL 5
Y^X
EEX
3
-

Why do you store X in R5 first? Why not simply ENTER Y^X?

(02-20-2018 01:49 AM)Gamo Wrote:  This steps work on the smaller number size because according to the book state that sometime the loop is too much then must change the loop count lower to successfully converge.

Sorry, I don't understand. What smaller number size do you mean? The loop is too much? The program converges if you reduce the number of loops? ?!?

But more important: what results do you get with that program?

Dieter
Find all posts by this user
Quote this message in a reply
02-20-2018, 09:28 AM (This post was last modified: 02-20-2018 09:34 AM by Gamo.)
Post: #10
RE: (11C) X to Power of X Equation
When I try X^X=10 with Newton's Method program which I used STO 5, RCL 5, Y^X, 10, - program steps and this work fine.
Then I try X^X=1000 Program keep running with Error 3. So I was thinking about loop count on this problem that might be the cause of the error or not enough memory.

About inserting program to solve problems.
What I think is that this program need to use repeat same register for each unknown X.
In the book example: X^6 - X - 1 = 0
Program: STO 5, 6, Y^X, RCL 5, -, 1,-

STO 5 for X^6
RCL 5, - for - X

Just wondering because program set up is not the same like 15C SOLVE

Gamo
Find all posts by this user
Quote this message in a reply
02-20-2018, 08:19 PM (This post was last modified: 02-20-2018 08:20 PM by Dieter.)
Post: #11
RE: (11C) X to Power of X Equation
(02-20-2018 09:28 AM)Gamo Wrote:  When I try X^X=10 with Newton's Method program which I used STO 5, RCL 5, Y^X, 10, - program steps and this work fine.
Then I try X^X=1000 Program keep running with Error 3. So I was thinking about loop count on this problem that might be the cause of the error or not enough memory.

No. Of course the program does not consume more or less memory if it runs the iteration loop 5, 10 or 50 times. I have looked at the program code, and this is what happens:

The program generates two different errors.

Error 4  is displayed if even after 50 loops the iteration has not converged. If really you got an Error 3 and not Error 4 (sure?) this is not what happened here. Technically this error is generated in line 53: if the DSE loop is left after 50 iterations the program tries to jump to LBL 9 – which does not exist.

Error 3  is displayed if the (approximated) derivative in the Newton formula is zero. In this case the Newton method cannot be used as it divides by this value, so this would lead to a division by zero. If you really got an Error 3 this is what must have happened. Both f(x) and f(x+δ) obviously had the same value.

Technically this error is generated in line 37/38: if the mentioned difference is zero, the program tries to access register ,9 – which does not exist (the program has more than 63 lines).

You may track down the problem by inserting a RCL 2 R/S (or PSE) right before the DSE in line 51. This way you see how the iteration converges – or not. Try it and write down the successive approximations. What was the initial guess you started with for Y=1000? Was it 4? 5? Or was it 0?

The Newton merhod for this particular function does not converge very well. It should work if the initial guess is sufficiently close to the solution. But in other cases the iteration will show very slow convergence or will even lead away from the solution, and you get an error. Try it. The program also implements a quite ..."creative" way of determining the value for δ. This causes even more problems here.

That's why I suggest solving a different equation. Instead of X^X = 1000 you better solve X*ln X = ln 1000. Both functions have the same solution, but the latter behaves far more relaxed and its slope changes much more moderately. So you may use this function at LBL C:

[ENTER] [LN] [x] [EEX] 3 [LN] [–]

Try different initial guesses and see what you get.

Finally an important note: you have to (!) initialize the program with [A] each time before you calculate a solution with [B]. The program overwrites the values that are set with [A], so you have to restore them before you start another iteration with [B].

(02-20-2018 09:28 AM)Gamo Wrote:  What I think is that this program need to use repeat same register for each unknown X.

No again. If X occurs several times in the function you may (!) store it somewhere and recall it from there each time an X occurs on the equation. But of course this is not required! You can just as well store X on the stack, for instance like this:

[ENTER] [ENTER] 6 [Y^X] [X<>Y] [–] 1 [–]

For the given example the STO 5 method is only a bit shorter and easier to understand for RPN beginners.
But calculating X^X on a RPN calculator and NOT doing it with a simple [ENTER] [Y^X]... that's almost ...weird. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
02-20-2018, 09:05 PM (This post was last modified: 02-20-2018 09:08 PM by Dieter.)
Post: #12
RE: (11C) X to Power of X Equation
(02-20-2018 08:19 PM)Dieter Wrote:  The Newton merhod for this particular function does not converge very well. It should work if the initial guess is sufficiently close to the solution. But in other cases the iteration will show very slow convergence or will even lead away from the solution, and you get an error.

To illustrate this point, here are the successive approximations for X^X–1000 = 0 for some different initial guesses, calculated with the exact derivative (and Excel ;-))

Code:
guess = 4

4
5,217892498
4,908845959
4,679436518
4,573633160
4,555955815
4,555535935
4,555535705
4,555535705

Fine. This seems to work.

Code:
guess = 3

3
20,17184124
19,92210893
19,67159726
19,42028894
19,16816596
18,91520959
18,66140031
18,40671780

This leads away from the solution and then moves veeeery slowly back in direction of the solution. It takes about 60 (!) iterations before the result is OK.

Code:
guess = 2

2
149,0634112
overflow

The iteration stops with an error because already the first new approximation becomes so large that the next step (requiring the evaluation of 149^149) will lead to an overflow error.

Code:
guess = 10

10
9,697206924
9,391568393
9,082908763
8,771032596
8,455721550
8,136730955
7,813786685
7,486584276

Again, the iteration converges veeery slowly.

That's why I suggest solving X*ln X = ln 1000 instead.

Dieter
Find all posts by this user
Quote this message in a reply
02-21-2018, 04:25 AM (This post was last modified: 02-21-2018 06:04 AM by Gamo.)
Post: #13
RE: (11C) X to Power of X Equation
Thank You Dieter

Now I understand how this equation not work with this program and your alternative equation work better.

For X^X=1000 changed equation to X*ln X = ln 1000

Program Steps: [ENTER] [LN] [x] [EEX] 3 [LN] [–]

Initial Guesses comparison:
2 > 4,555535706
3 > 4,555535705
4 > 4,555535705
5 > 4,555535705
6 > 4,555535705
.
.
.
10 > 4,555535705

The closer guess to the root the faster the computation.

Gamo




Gamo
Find all posts by this user
Quote this message in a reply
Post Reply 




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