(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:
Gamo |
|||
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 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 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 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 |
|||
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 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 |
|||
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 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 Dieter |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)