Post Reply 
(12C) X to Power of X Equation
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 


Messages In This Thread
(12C) X to Power of X Equation - Gamo - 02-18-2018, 09:15 AM
RE: (12C) X to Power of X Equation - Dieter - 02-18-2018 04:58 PM



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