HP Forums
Gamma function using Spouge Approximation - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP-65/67/97 Software Library (/forum-12.html)
+--- Thread: Gamma function using Spouge Approximation (/thread-149.html)



Gamma function using Spouge Approximation - Namir - 12-18-2013 06:00 AM

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



RE: Gamma function using Spouge Approximation - Willy R. Kunz - 06-08-2014 03:45 PM

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.


RE: Gamma function using Spouge Approximation - Namir - 06-13-2014 12:35 PM

Thanks for your correction Willy. I corrected step 68 as you suggested.

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

Namir


RE: Gamma function using Spouge Approximation - Willy R. Kunz - 06-13-2014 09:57 PM

(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



RE: Gamma function using Spouge Approximation - bshoring - 03-21-2015 03:26 AM

Thanks Namir, for this program. I ran several samples and got a high degree of accuracy for the Gamma function.

Regards,
Bob


RE: Gamma function using Spouge Approximation - bshoring - 04-07-2015 09:43 PM

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