Gamma Function Using Spouge's Method
08-12-2015, 09:11 PM (This post was last modified: 08-12-2015 10:59 PM by Dieter.)
Post: #6
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Gamma Function Using Spouge's Methjod
(08-12-2015 05:39 PM)Dieter Wrote:  Addendum: This also means that a value as high as a=12,5 does not make much sense here. Try Namir's program with a=7 (replace 12.5 with 7 and 1.012 with 1.006). My tests returned results at least as accurate as with a=12,5 (mostly even better) while the program runs about twice as fast.

FTR, here is my implementation for the '41, based on a "hard-wired" a=7.
Like the factorial function on various other HPs, it actually calculates Γ(x+1).

Code:
01 LBL "GAM+1" 02 STO 00 03 6 04 + 05 STO 04 06 5,5 07 STO 02 08 INT 09 FACT 10 STO 03 11 SIGN 12 STO 01 13 CLx 14 LBL 01 15 RCL 01 16 RCL 02 17 y^x 18 RCL 01 19 e^x 20 * 21 RCL 03 22 / 23 RCL 04 24 / 25 + 26 RCL 02 27 INT 28 X=0? 29 GTO 02 30 CHS 31 ST/ 03 32 SIGN 33 ST- 01 34 ST+ 02 35 ST+ 04 36 RDN 37 GTO 01 38 LBL 02 39 RDN 40 ABS 41 Pi 42 ST+ X 43 SQRT 44 + 45 RCL 00 46 7 47 + 48 STO 03 49 RCL 00 50 ,5 51 + 52 y^x 53 * 54 RCL 03 55 e^x 56 / 57 END

Since it doesn't seem to get much better than 8 valid digits in the final result, a=7 is sufficient here. Evaluated exactly, the largest relative error is approx. 2,3 E–9. Actually the error may be slightly higher. But it should be less than in the original a=12,5 version.

Some examples:
Code:
 3   XEQ"GAM+1"  =>  5,999999994  5   XEQ"GAM+1"  =>  120,0000000  7   XEQ"GAM+1"  =>  5040,000009 8,35 XEQ"GAM+1"  =>  85899,08333      (exact: ...363) 17,3 XEQ"GAM+1"  =>  8,416039696 E+14 (exact: ...738) 50,5 XEQ"GAM+1"  =>  2,166683759 E+65 (exact: ...771)

The current version throws an OUT OF RANGE error for x > 54,9. Maybe this can be improved somehow.

Edit: the following modification may be a solution. However, the resulting accuracy is slightly less than in the first version.

Code:
... 45 RCL 00 46 7 47 + 48 STO 03 49 LN 50 RCL 00 51 ,5 52 + 53 * 54 RCL 03 55 - 56 e^x 57 * 58 END

This way x=69,9575744 returns 9,999997034 E+99 (exact: ...7560).

Dieter
 « Next Oldest | Next Newest »

 Messages In This Thread Gamma Function Using Spouge's Method - Namir - 12-18-2013, 12:55 AM RE: Gamma Function Using Spouge's Methjod - lcwright1964 - 08-07-2015, 07:23 PM RE: Gamma Function Using Spouge's Methjod - lcwright1964 - 08-12-2015, 04:03 AM RE: Gamma Function Using Spouge's Methjod - Dieter - 08-12-2015, 05:39 PM RE: Gamma Function Using Spouge's Methjod - lcwright1964 - 08-12-2015, 06:03 PM RE: Gamma Function Using Spouge's Methjod - Dieter - 08-12-2015 09:11 PM RE: Gamma Function Using Spouge's Methjod - Ángel Martin - 08-19-2015, 08:56 PM RE: Gamma Function Using Spouge's Methjod - Dieter - 08-20-2015, 11:36 AM RE: Gamma Function Using Spouge's Methjod - lcwright1964 - 08-20-2015, 07:49 PM RE: Gamma Function Using Spouge's Methjod - Ángel Martin - 08-21-2015, 09:48 AM RE: Gamma Function Using Spouge's Methjod - lcwright1964 - 08-22-2015, 02:09 AM RE: Gamma Function Using Spouge's Methjod - Ángel Martin - 08-22-2015, 08:35 AM RE: Gamma Function Using Spouge's Methjod - lcwright1964 - 08-22-2015, 08:58 AM RE: Gamma Function Using Spouge's Methjod - Ángel Martin - 08-22-2015, 10:45 AM RE: Gamma Function Using Spouge's Methjod - lcwright1964 - 08-19-2015, 05:32 PM RE: Gamma Function Using Spouge's Methjod - Dieter - 08-20-2015, 12:36 PM RE: Gamma Function Using Spouge's Methjod - Thomas Klemm - 08-20-2015, 08:22 PM RE: Gamma Function Using Spouge's Methjod - lcwright1964 - 08-22-2015, 09:57 AM RE: Gamma Function Using Spouge's Methjod - Ángel Martin - 08-22-2015, 01:17 PM RE: Gamma Function Using Spouge's Methjod - lcwright1964 - 08-22-2015, 11:51 PM RE: Gamma Function Using Spouge's Methjod - Dieter - 08-23-2015, 09:01 PM RE: Gamma Function Using Spouge's Methjod - lcwright1964 - 08-24-2015, 08:12 AM RE: Gamma Function Using Spouge's Methjod - lcwright1964 - 08-24-2015, 09:23 AM RE: Gamma Function Using Spouge's Methjod - Dieter - 08-24-2015, 07:32 PM RE: Gamma Function Using Spouge's Methjod - lcwright1964 - 08-24-2015, 08:40 PM RE: Gamma Function Using Spouge's Methjod - Dieter - 08-24-2015, 11:14 PM RE: Gamma Function Using Spouge's Methjod - lcwright1964 - 08-25-2015, 01:56 AM RE: Gamma Function Using Spouge's Methjod - Dieter - 08-25-2015, 06:48 PM RE: Gamma Function Using Spouge's Methjod - Dieter - 08-27-2015, 11:21 PM RE: Gamma Function Using Spouge's Methjod - Dieter - 09-15-2015, 06:43 PM RE: Gamma Function Using Spouge's Methjod - lcwright1964 - 08-25-2015, 11:29 PM RE: Gamma Function Using Spouge's Methjod - Dieter - 08-26-2015, 09:50 AM RE: Gamma Function Using Spouge's Methjod - lcwright1964 - 08-26-2015, 12:50 PM RE: Gamma Function Using Spouge's Methjod - Dieter - 08-26-2015, 05:08 PM

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