(12C) Stirling's approximation
|
10-24-2017, 05:35 AM
(This post was last modified: 10-24-2017 09:15 AM by Gamo.)
Post: #1
|
|||
|
|||
(12C) Stirling's approximation
For when you need answer from Decimal Factorial with your HP 12C
From Wikipedia: In mathematics, Stirling's approximation (or Stirling's formula) is an approximation for factorials. It is a good-quality approximation, leading to accurate results even for small values of n. Program: Code:
Example: Clear Register f [REG] [R/S] result 0 (Initialize) 2.34! ------> 2.34 [R/S] result 2.7976...... 4.32! ------> 4.32 [R/S] result 39.2945.... 5.43! ------> 5.43 [R/S] result 254.0337... Gamo |
|||
11-04-2017, 05:26 AM
(This post was last modified: 11-19-2017 01:44 AM by Gamo.)
Post: #2
|
|||
|
|||
RE: (12C) Stirling's approximation
N! approximation using Forsyth's formula with shorter program steps.
Code:
Example: input N [R/S] 2.34! ------> 2.34 [R/S] result 2.7971...... 4.32! ------> 4.32 [R/S] result 39.2928.... 5.43! ------> 5.43 [R/S] result 254.0266... Gamo |
|||
11-04-2017, 02:01 PM
Post: #3
|
|||
|
|||
RE: (12C) Stirling's approximation
(11-04-2017 05:26 AM)Gamo Wrote: N! approximation using Forsyth's formula with shorter program steps. Instead of 2 [y^x] you should use [ENTER] [x] which is much faster (and sometimes even more accurate). And why don't you simply use 6 [1/x] instead of 0,1667 ?-) Finally, once again the ENTER is not required and should be omitted. This leads to the following version, here with a few more digits in sqrt(2pi) and without any registers: Code: ENTER This gets even a tiiiny bit closer to the true results: 2.34 [R/S] => 2.7971... 4.32 [R/S] => 39.2931... 5.43 [R/S] => 254.0287... And it accurately overflows for x > 69,95757445 Dieter |
|||
11-05-2017, 07:39 AM
Post: #4
|
|||
|
|||
RE: (12C) Stirling's approximation
Dieter Thank You
Totally forgot about 1/6 by using [ 1/x ] And your program is really improve the accuracy. Gamo |
|||
11-06-2017, 01:41 PM
Post: #5
|
|||
|
|||
RE: (12C) Stirling's approximation
(11-05-2017 07:39 AM)Gamo Wrote: Totally forgot about 1/6 by using [ 1/x ] To be honest, the change in accuracy is negligible. The essential message was: please, do not use 2 [y^x] for squaring. [ENTER] [x] is much faster, sometimes more accurate and it even sets LastX correctly. Dieter |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)