(12C) Stirling's approximation - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (12C) Stirling's approximation (/thread-9355.html) |
(12C) Stirling's approximation - Gamo - 10-24-2017 05:35 AM 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 RE: (12C) Stirling's approximation - Gamo - 11-04-2017 05:26 AM 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 RE: (12C) Stirling's approximation - Dieter - 11-04-2017 02:01 PM (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 RE: (12C) Stirling's approximation - Gamo - 11-05-2017 07:39 AM Dieter Thank You Totally forgot about 1/6 by using [ 1/x ] And your program is really improve the accuracy. Gamo RE: (12C) Stirling's approximation - Dieter - 11-06-2017 01:41 PM (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 |