Post Reply 
(12C) X to Power of X Equation
02-18-2018, 09:15 AM (This post was last modified: 02-18-2018 09:19 AM by Gamo.)
Post: #1
(12C) 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]
1000 R/S result 4.544975
1000 R/S result 4.555231
1000 R/S result 4.555527
1000 R/S result 4.555535

About 5 repeated R/S will give accuracy to 6 decimal digits.

Since HP-12C doesn't have Iteration Function like DSE or ISG

Not sure if I implement this the right way or not. Any change is very welcome.

Program:
Code:

01 LN
02 ENTER
03 ENTER
04 ENTER
05 RCL 1
06 LN
07 /
08 RCL 1
09 +
10 2
11 /
12 STO 1
13 LN
14 /
15 RCL 1
16 +
17 2
18 /
19 STO 1
20 STO 0
21 ENTER
22 ENTER
23 ENTER
24 RCL 0
25 -
26 ENTER
27 x
28 √
29 X<>Y
30 EXX
31 8
32 /
33 X<>Y
34 X<=Y
35 GTO 39
36 R↓
37 R↓
38 GTO 20
39 R↓
40 R↓

Gamo
Find all posts by this user
Quote this message in a reply
02-18-2018, 01:41 PM (This post was last modified: 02-18-2018 02:06 PM by Dieter.)
Post: #2
RE: (12C) X to Power of X Equation
(02-18-2018 09:15 AM)Gamo Wrote:  Here is the approximation of the equation of X^X=Y
...
Not sure if I implement this the right way or not. Any change is very welcome.

OK then. First, line 06...12 and 13...19 are exactly the same. Then in line 20 you store something in R0, fill the stack with it and subtract R0 again. So this always yields zero and the following test is always true. ?!?

Here is a short version of your algorithm.

Code:
01 STO 1   // store approximation
02 X<>Y
03 LN
04 ENTER   // fill stack with ln Y
05 ENTER
06 ENTER
07 RCL 1   // start calculating new approximation
08 LN
09 /       // ln Y : LN X
10 RCL 1
11 +
12 2
13 /       // new approx. = (X + ln Y : lnX) : 2
14 STO 1   // store the result again
15 R/S
16 GTO 08  // and repeat

Enter Y and a first approximation:

f[PRGM]
1000 [ENTER] 4

[R/S] 4,491446
[R/S] 4,544975
[R/S] 4,553747
[R/S] 4,555231
[R/S] 4,555484
[R/S] 4,555527
[R/S] 4,555534
[R/S] 4,555535
[R/S] 4,555536
[R/S] 4,555536

Since your version always calculates two (!) successive approximations (twice the same code) the above results match every second one of yours.

You can also have an initial guess calculated by the program so that you only have to enter Y. This has been shown recently in the 11C version, on the 12C it can be done this way:

Code:
01 LN
02 STO 0
03 1
04 +
05 LN
06 ENTER
07 LN
08 0
09 x<=y?
10 X<>Y
11 X<>Y
12 R↓
13 -
14 e^x
15 R/S
16 ENTER
17 ENTER
18 ENTER
19 RCL 0
20 X<>Y
21 LN
22 /
23 +
24 2
25 /
26 GTO 15

f[PRGM]
1000
[R/S] 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

When the new approximation is displayed you can press [X<>Y] to compare it with the previous one.

Now let's see if the iteration process can be done automatically. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
02-18-2018, 03:17 PM
Post: #3
RE: (12C) X to Power of X Equation
(02-18-2018 01:41 PM)Dieter Wrote:  Now let's see if the iteration process can be done automatically. ;-)

Indeed the 11C version proposed in the other thread can be adapted for the 12C.
Including a loop counter. ;-)

Code:
01 LN
02 STO 0
03 1
04 +
05 LN
06 ENTER
07 LN
08 0
09 x<=y?
10 X<>Y
11 X<>Y
12 R↓
13 -
14 5
15 STO 1
16 R↓
17 ENTER
18 ENTER
19 ENTER
20 RCL 0
21 X<>Y
22 e^x
23 /
24 -
25 X<>Y
26 1
27 +
28 /
29 LstX
30 1/x
31 1
32 +
33 X<>Y
34 x
35 LstX
36 X<>Y
37 2
38 /
39 CHS
40 1
41 +
42 /
43 -
44 -
45 x=0?
46 GTO 57
47 1
48 STO-1
49 RCL 1
50 x=0?
51 GTO 57
52 R↓
53 R↓
54 R↓
55 LstX
56 GTO 17
57 LstX
58 ST0/0
59 e^x
60 RCL 0
61 GTO 00

The program works for input > 1.

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

Example:

1000 [R/S] => 4,555535705
   [X<>Y]   => 4,555535705

EEX 9 [R/S] => 9,295086903
   [X<>Y]    => 9,295086898

Here in fact the exact result is right in the middle: 9,295086900 376...

Dieter
Find all posts by this user
Quote this message in a reply
02-18-2018, 04:58 PM (This post was last modified: 02-19-2018 08:45 AM by Dieter.)
Post: #4
RE: (12C) X to Power of X Equation
(02-18-2018 01:41 PM)Dieter Wrote:  Now let's see if the iteration process can be done automatically. ;-)

Here is another more compact version. It uses a simple yet effective initial estimate. Instead of xx = y  it solves  x · ln x = ln y, which has better numeric properties. The derivative is 1 + ln x which leads to a short and simple implementation of Newton's method:

Code:
01 LN
02 STO 0
03 ,
04 7
05 3
06 y^x
07 1
08 +
09 5
10 STO 1
11 R↓
12 ENTER
13 ENTER
14 LN
15 x
16 1
17 STO-1
18 LstX
19 +
20 X<>Y
21 RCL 0
22 -
23 X<>Y
24 /
25 -
26 X<>Y
27 Δ%
28 2
29 EEX
30 3
31 +
32 LstX
33 -
34 RCL 1
35 x
36 x=0?
37 GTO 40
38 R↓
39 GTO 12
40 R↓
41 GTO 00

This should work for any input ≥ 1.

The exit condition is a relative difference of less than 5 E–7 percent (i.e. 5 E–9) between the last two approximations. This can be modified by changing the exponent in line 31 (the higher, the earlier the iteration terminates). There also is a counter as a safeguard: if the last relative difference does not round to zero, it definitely will after it has been multiplied by the counter which will eventually become zero.

Again, the last two approximations are returned in X and Y.

1000 [R/S] => 4,555535705
   [X<>Y]   => 4,555535705

3125 [R/S] => 5,000000001
   [X<>Y]   => 4,999999999

Edit: here is another version which is even slighty shorter. The exit condition now is a relative error < 1 E–7 percent. This can be adjusted by the constant in line 28...30 which simply is the reciprocal of the error threshold (in percent). So if, for example, you want the iteration to exit at a relative error of 2 E–8, that's 2 E–6 percent and 1/2E–6 = 5 E5 which then is the value in line 28...30.

Code:
01 LN
02 STO 0
03 ,
04 7
05 3
06 y^x
07 1
08 +
09 5
10 STO 1
11 R↓
12 ENTER
13 ENTER
14 LN
15 x
16 1
17 STO-1
18 LstX
19 +
20 X<>Y
21 RCL 0
22 -
23 X<>Y
24 /
25 -
26 X<>Y
27 Δ%
28 1
29 EEX
30 7
31 x
32 INTG
33 RCL 1
34 x
35 x=0?
36 GTO 38
37 GTO 11
38 +
39 GTO 00

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




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