Post Reply 
(42s) Hypergeometric function for HP-42s (UPDATED)
10-30-2023, 05:29 PM (This post was last modified: 11-02-2023 11:04 AM by Namir.)
Post: #1
(42s) Hypergeometric function for HP-42s (UPDATED)
Hypergeometric function for HP-42s
=================================

Code calculates values for the hypergeometric function F(alpha, beta, gamma, x). The code uses the gamma function to help calculate the value of the hypergeometric function.

Memory Map
=========

Code:
R00 = x
R01 = alpha
R02 = beta
R03 = gamma_var
R04 = toler
R05 = sum - > fx value
R06 = k (loop control variable).
R11 = gamma(alpha)
R12 = gamma(beta)
R13 = gamma(gamma_var)

HP-42S Listing
=========

NOTE: The following code was updated per suggestions of Velentin Alibillo to shorten the code by a few statements.

Code:
01 LBL "HGFX"
02 A^B^C^
03 PROMPT
04 STO 00
05 RDN
06 STO 03
07 GAMMA
08 STO 13
09 RDN
10 STO 02
11 GAMMA
12 STO 12
13 RDN
14 STO 01
15 GAMMA
16 STO 11
17 TOLER?
18 PROMPT
19 STO 04
20 1
21 STO 06
22 0
23 STO 05
24 LBL 00
25 1
26 STO+ 0
27 RCL 01
28 RCL+ 0
29 GAMMA
30 RCL 11
31 ÷
32 RCL 03
33 RCL+ 0
34 GAMMA
35 RCL 13
36 ÷
37 ÷
38 RCL 02
39 RCL+ 0
40 GAMMA
41 RCL 12
42 ÷
43 ×
44 RCL 05
45 N!
46 ÷
47 RCL 00
48 RCL 05
49 Y^X
50 ×
51 STO+ 0
52 ABS
53 RCL 04
54 X=Y?
55 GTO 00
56 RCL 06
57 RTN

Usage
=====

1) Press [XEQ] HGFX. The program displays the prompt "A^B^C^X?"
2) Enter the value for parameter alpha and press ENTER.
3) Enter the value for parameter beta and press ENTER.
4) Enter the value for parameter gamma and press ENTER.
5) Enter the value for x and press R/S. The program displays the prompt "TOLER?"
6) Enter a small value for the tolerance and press R/S.
7) The program displays the value of the hypergeometric function.

Example
=======

To calculate F(1.5, 1.5, 2.5, 0.3), perform the following steps:

1) Press [XEQ] HGFX. The program displays the prompt "A^B^C^X?"
2) Enter the value 1.5 for parameter alpha and press ENTER.
3) Enter the value 1.5 for parameter beta and press ENTER.
4) Enter the value 2.5 for parameter gamma and press ENTER.
5) Enter the value 0.3 for x and press R/S. The program displays the prompt "TOLER?"
6) Enter a small value 1E-15 for the tolerance and press R/S.
7) The program displays 1.36956073 as the value of the hypergeometric function.
Find all posts by this user
Quote this message in a reply
11-01-2023, 02:35 AM
Post: #2
RE: Hypergeometric function for HP-42s
.
Hi, Namir,

(10-30-2023 05:29 PM)Namir Wrote:  HP-42S Listing
=========

01 LBL "HGFX"
02 A^B^C^X?
03 PROMPT
04 STO 00
05 RDN
06 STO 03
07 RDN
8 STO 02
9 RDN
10 STO 01
11 TOLER?
12 PROMPT
13 STO 04
14 1
15 STO 06
16 0
17 STO 05
18 RCL 01
19 GAMMA
20 STO 11
21 RCL 02
22 GAMMA
23 STO 12
24 RCL 03
25 GAMMA
26 STO 13
27 LBL 00
28 1
29 STO+ 05
30 RCL 01
31 RCL 05
32 +
33 GAMMA
34 RCL 11
35 ÷
36 RCL 03
37 RCL 05
38 +
39 GAMMA
40 RCL 12
41 ÷
42 ÷
43 RCL 02
44 RCL 05
45 +
46 GAMMA
47 RCL 13
48 ÷
49 ×
50 RCL 05
51 N!
52 ÷
53 RCL 00
54 RCL 05
55 Y^X
56 ×
57 STO+ 06
58 ABS
59 RCL 04
60 X=Y?
61 GTO 00
62 RCL 06
63 RTN

Some hopefully useful comments:
    1. Change the Subject of your OP from "Hypergeometric function for HP-42s" to "(42S) Hypergeometric function", to conform to the titling style in this forum.

    2. I've seen that this program for the 42S is essentially the same as the one you recently posted to the 41C Library, essentially just replacing the calls to your GAM4 program by the 42S built-in GAMMA function.

    However, the 42S also has RCL arithmetic (which the 41C lacks) and it can be put to good use in several places, for instance:

      30 RCL 01
      31 RCL 05
      32 +

    can be replaced by:

      30 RCL 01
      31 RCL+ 05

    saving one line (32 + is no longer necessary). You can do this with lines 30-32, 34-35 (RCL÷ 11), 36-38, 40-41, 43-45 and 47-48, saving 6 lines in all.

    3. You can also save further lines replacing this code:
      ...
      06 STO 03
      07 RDN
      08 STO 02
      09 RDN
      10 STO 01
      11 TOLER?
      12 PROMPT
      13 STO 04
      14 1
      15 STO 06
      16 0
      17 STO 05
      18 RCL 01
      19 GAMMA
      20 STO 11
      21 RCL 02
      22 GAMMA
      23 STO 12
      24 RCL 03
      25 GAMMA
      26 STO 13

      27 LBL 00

    by this code:
      ...
      06 STO 03
      07 GAMMA
      08 STO 13

      09 RDN
      10 STO 02
      11 GAMMA
      12 STO 12

      13 RDN
      14 STO 01
      15 GAMMA
      16 STO 11

      17 TOLER?
      18 PROMPT
      19 STO 04
      20 1
      21 STO 06
      22 0
      23 STO 05
      24 LBL 00
      ...

    saving an additional 3 lines with no change in functionality (just very slightly faster.)
Best regards.
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
11-01-2023, 06:13 PM
Post: #3
RE: Hypergeometric function for HP-42s
Yes, but RCL+ nn always takes 3 bytes, while RCL nn + only takes 2, for n=00 to 15 included.
Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
11-02-2023, 02:45 AM
Post: #4
RE: (42s) Hypergeometric function https://www.hpmuseum.org/forum/index.phpfor HP-42s
Thanks Valentine for your tips and comments. Will update the code!

Namir
Find all posts by this user
Quote this message in a reply
11-02-2023, 11:05 AM
Post: #5
RE: (42s) Hypergeometric function for HP-42s (UPDATED)
HP-42S listing in first posting of this thread has been updated.

Namir
Find all posts by this user
Quote this message in a reply
Post Reply 




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