Post Reply 
Gamma function using Spouge Approximation
12-18-2013, 06:00 AM (This post was last modified: 06-13-2014 12:34 PM by Namir.)
Post: #1
Gamma function using Spouge Approximation
HP-67 Implementation

Memory Map

R0 = x and = x-1
R1 = a
R2 = CHS
R3 = Sum
R4 = Integer part of I, x+a
R5 = sqrt(2*pi)
RI = I

Listiing

Code:
1 LBL A
2 1
3 -
4 STO 0
5 1
6 2
7 .
8 5
9 STO 1 # a = 12.5
10 1
11 STO 3 # Sum = 1
12 CHS
13 STO 2 # CHS = -1
14 2
15 PI
16 *
17 SQRT
18 STO 5 # sqrt(2*pi)
19 12
20 CHS
21 STI # set up loop control variable
22 LBL 0 # start the loop
23 RCL 2
24 RCL 5
25 /
26 RCI
27 ABS
28 STO 4
29 1
30 -
31 N!
32 /
33 RCL 1
34 RCL 4
35 -
36 RCL 4
37 0
38 .
39 5
40 -
41 Y^X
42 *
43 RCL 1
44 RCL 4
45 -
46 EXP
47 * # calculate C
48 RCL 4
49 RCL 0
50 +
51 /
52 STO+ 3 # Sum = Sum + C/(X+I)
53 RCL 2
54 CHS
55 STO 2 # CHS = -CHS
56 ISZ # end of loop
57 GTO 0
58 RCL 0
59 RCL 1
60 +
61 STO 4
62 RCL 0
63 0.5
64 +
65 Y^X
66 RCL 4
67 EXP
68 /
69 RCL 5
70 *
71 RCL 3
72 *
73 R/S
74 GTO A
Find all posts by this user
Quote this message in a reply
06-08-2014, 03:45 PM
Post: #2
RE: Gamma function using Spouge Approximation
Hi Namir,
thanks for sharing this program. I pasted it into my RPN-97 emulator on the iPad and it works just fine, but only if step 68 is changed to a division.
Find all posts by this user
Quote this message in a reply
06-13-2014, 12:35 PM
Post: #3
RE: Gamma function using Spouge Approximation
Thanks for your correction Willy. I corrected step 68 as you suggested.

Also thanks for fantastic HP-67/97 emulators for the iPad!

Namir
Find all posts by this user
Quote this message in a reply
06-13-2014, 09:57 PM
Post: #4
RE: Gamma function using Spouge Approximation
(06-13-2014 12:35 PM)Namir Wrote:  Thanks for your correction Willy. I corrected step 68 as you suggested.

Also thanks for fantastic HP-67/97 emulators for the iPad!

Namir

Thank you for the kudos. BTW, your sometimes "unorthodox" listings caused me quite a bit of headache while implementing the new source code translation capability of the emulators. But finally things are coming together.

So
Code:

25 2
26 4
27 0
28 CHS
29 GSB 2
30 252
31 GSB 2
32 120
translates into:
Code:

001:  02         2  
002:  04         4  
003:  00         0  
004:  42         CHS  
005:  31 22 02   GSB 2
006:  02         2  
007:  05         5  
008:  02         2  
009:  31 22 02   GSB 2
010:  01         1  
011:  02         2  
012:  00         0
and
Code:

62 RCL 0
63 0.5
into:
Code:

001:  34 00      RCL 0  
002:  00         0  
003:  83         .  
004:  05         5

In fact, you may even enter
Code:

a
B
i
I
and get:
Code:

001:  32 22 11   GSB a
002:  31 22 12   GSB B
003:  34 24      RCL (i)  
004:  35 34      RC I
Find all posts by this user
Quote this message in a reply
03-21-2015, 03:26 AM
Post: #5
RE: Gamma function using Spouge Approximation
Thanks Namir, for this program. I ran several samples and got a high degree of accuracy for the Gamma function.

Regards,
Bob
Find all posts by this user
Quote this message in a reply
04-07-2015, 09:43 PM (This post was last modified: 04-30-2015 09:40 PM by bshoring.)
Post: #6
RE: Gamma function using Spouge Approximation
So far I am finding this program yields correct results for any positive number up to 55. For negative numbers (non-integer) I have gotten correct results on all the ones I have tried so far.

I have also modified the program somewhat to work on my HP-38C as well as the iOS emulator for HP-25 (GO-25 SciRPN) which has a capacity of 99 program steps. The latter was more of a challenge as the HP-25 has no factorial or ISZ functions so those have to be re-created using additional program steps.

Regards,
Bob
Find all posts by this user
Quote this message in a reply
Post Reply 




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