Showing posts with label combination. Show all posts
Showing posts with label combination. Show all posts

Saturday, March 14, 2026

Commodore P50 Programs

Commodore P50 Programs



A collection of programs from the vintage Commodore P50 from 1978. Check out my review from last April: https://edspi31415.blogspot.com/2025/04/spotlight-commodore-p50.html.



Air Density


This equation calculates air density, in m/kg³ given the temperature of Celsius. The standard equations are used.


ρ = p ÷ (R * (T°C + 273.15)) ≈ 359.98728 ÷ (T°C + 273.15)

p = 101,325 Pa (absolute pressure)

R = 287.05 J/(kg * K) (specific gas constant)

p/R = 101325 / 287.05 ≈ 359.98728



With limited storage space of 24 steps, the equation had to be simplified.

(The step numbers are for reference, since steps cannot be reviewed on the P50.)



Start with temperature in the display. Press GOTO 00, R/S. The air density is displayed.

00 +

01 2

02 7

03 3

04 .

05 1

06 5

07 =

08 1/x

09 ×

10 3

11 5

12 2

13 .

14 9

15 8

16 7

17 2

18 8

19 =

20 r/s

21 GOTO

22 00


Examples:


Example 1: Input: 0°C, Output: 1.2922837 m/kg³

Example 2: Input: 15°C, Output: 1.2250123 m/kg³

Example 3: Input: 37.8°C, Output: 1.1351898 m/kg³



Speed of Sound



This equation calculates the speed of sound (in dry air) in m/s given the temperature of Celsius.

c_air ≈ 20.05 * √(273.15 + T°C)



Start with temperature in the display. Press GOTO 00, R/S. The speed of air is displayed.

00 +

01 2

02 7

03 3

04 .

05 1

06 5

07 =

08 √x

09 ×

10 2

11 0

12 .

13 0

14 5

15 =

16 r/s

17 GOTO

18 00


Examples:

Example 1: Input: 0°C, Output: 331.37137 m/s

Example 2: Input: 20°C, Output: 343.28856 m/s

Example 3: Input: 37.8°C, Output: 353.55718 m/s



Decibel Gain/Loss from Power Ratio



dB = 10 * log(power output ÷ power input)



Start with power output. Press GOTO 00, R/S. Then enter power input, press R/S. The decibel gain/loss is displayed.


00 ÷

01 r/s

02 =

03 log

04 ×

05 1

06 0

07 =

08 r/s

09 GOTO

10 00


Examples:

Example 1: power output = 25 W, power input = 5 W

Input: 25 GOTO 00 r/s, 5 r/s. Output: 6.9897 dB

Example 2: power output = 30 W, power input = 42 W

Input: 30 GOTO 00 r/s, 42 r/s. Output: -1.4612804 dB

Example 3: power output = 3 W, power input = 1 W

Input: 3 GOTO 00 r/s, 1 r/s. Output: 4.7712125 dB



“Radio Mathematics” ARRL. Retrieved November 1, 2025. https://www.arrl.org/files/file/ARRL%20Handbook%20Supplemental%20Files/2023%20Edition/Radio%20Supplement.pdf



Plus or Minus Operation



This program calculates a ± b (a + b and a – b). The program leaves a – b in the display and a + b in memory, which can be toggled by the memory exchange [ x ←→ M ] key.


The program uses the memory exchange key. Enter b (the term to both be added and subtracted first), then a.


00 STO

01 r/s

02 +

03 RCL

04 =

05 r/s

06 x ←→ M

07 ×

08 2

09 =

10 ±

11 +

12 RCL

13 =

14 r/s

15 GTO

16 00


Examples:

Remember, enter the second number (b) first.

Example 1: 5 ± 9

Input: 9 GOTO 00 r/s, 5, r/s. Output: 14 r/s -4

Example 2: 36 ± 20

Input: 20 GOTO 00 r/s, 36 r/s. Output: 56 r/s 16

Example 3: 310 ± 240

Input: 240 GOTO 00 r/s, 310 r/s. Output: 550 r/s 70



Combination



This is the combination function:



nCr = n! ÷ (r! * (n – r)!)



Due to only having one memory register and the factorial function does not distribute, one of the arguments (r) will need to be entered twice.



Input: n GOTO 00 r/s, r r/s, r r/s (again). Output: nCr.



00 STO

01 -

02 r/s

03 =

04 n!

05 1/x

06 ×

07 RCL

08 n!

09 ÷

10 r/s

11 n!

12 =

13 r/s

14 GOTO

15 00



Examples:

Example 1: 52 C 5

Input: 52 GOTO 00 r/s, 5 r/s, 5 r/s. Output: 2,598,960

Example 2: 34 C 12

Input: 34 GOTO 00 r/s, 12, r/s, 12 r/s. Output: 5.4835404 E 08

Example 3: 10 C 4

Input: 10 GOTO 00 r/s, 4 r/s, 4 r/s. Output: 210


Eddie


All original content copyright, © 2011-2026. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.


Saturday, April 29, 2023

TI-74 and Python (Casio fx-9750GIII): Probability

TI-74 and Python (Casio fx-9750GIII):  Probability



Today's program illustrates an approach from both the BASIC and Python programming languages. 


The program offers the user to calculate common probability problems:



1)  n!:  factorial of an integer

2)  nCr:  combinations without replacement

3)  nPr:  permutations

4)  nHr:  combinations with replacement

5) bday:  probability that n people do not share a category in common from a size of categories (i.e. birthday problem:  How many people in a room don't share a birthday?)



TI-74 BASICALC Program


200 REM probability

202 INPUT "1)n! 2)nCr 3)nPr 4)nHr 5)bday "; I

204 IF I<5 THEN INPUT "n? "; N

206 IF I>1 AND I<5 THEN INPUT "r? "; R

208 ON I GOTO 220,240,260,280,300


220 X=N

222 GOSUB 320

224 PRINT "n! = "; F: PAUSE

226 GOTO 340


240 Z=1: FOR K=(N-R+1) TO N: Z=Z*K: NEXT K

242 X=R: GOSUB 320

244 Z=Z/F

246 PRINT "nCr = "; Z: PAUSE

248 GOTO 340


260 Z=1: FOR K=(N-R+1) TO N: Z=Z*K: NEXT K

262 PRINT "nPr = "; Z: PAUSE

264 GOTO 340


280 Z=1: FOR K=N TO (N+R-1): Z=Z*K: NEXT K

282 X=R: GOSUB 320: Z=Z/F

284 PRINT "nHr = "; Z: PAUSE

286 GOTO 340


300 INPUT "# categories? "; R

302 INPUT "Sample size? "; N

304 Z=1: FOR K=1 TO (N-1): Z=Z*(1-K/R): NEXT K

306 PRINT "P(all unique) = "; Z: PAUSE

308 GOTO 340


320 F=1

322 FOR K=1 TO X: F=F*K: NEXT K

324 RETURN


340 INPUT "Again? 0:No, 1:Yes "; A

342 IF A=1 THEN 202

344 IF A=0 THEN STOP

346 GOTO 340



Python Program:  prob.py 


Program completed with the Casio fx-9750GIII.


# probability

from math import *


def fact(x):

  f=1

  for k in range(1,x+1):

    f*=k    

  return f



fc=1


while fc!=0:

  print("1)n! 2)nCr")

  print("3)nPr 4)nHr")

  print("5)bday")

  ch=int(input())

  if ch<5:

    n=int(input("n? "))

  if ch>1 and ch<5:

    r=int(input("r? "))

  if ch==1:

    f=fact(n)

    print("n! = "+str(f))

  if ch==2:

    f=fact(n)/(fact(n-r)*fact(r))

    print("nCr = "+str(f))

  if ch==3:

    f=fact(n)/fact(n-r)

    print("nPr = "+str(f))

  if ch==4:

    f=fact(n+r-1)/(fact(r)*fact(n-1))

    print("nHr = "+str(f))

  if ch==5:

    r=int(input("# categories? "))

    n=int(input("Sample size? "))

    f=1

    for k in range(n):

      f*=1-k/r

    print("p(all unique)=")

    print(str(f))

  print("Again? 0)no 1)yes")

  fc=int(input())    


Examples


1) n!  

13! = 6227020800


2) nCr

n = 13, r = 6; result:  1716


3) nPr

n = 13, r = 6; result:  1235520


4) nHr

n = 13, r = 6; result:  18564


5) bday

# categories: 13

Sample size: 6

Result:  P(all unique) = .2559703523



Wishing you an excellent day.   More BASIC and Python programming coming your way tomorrow!


Eddie


All original content copyright, © 2011-2023.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Wednesday, August 31, 2016

HP 12C: Combination/Binomial Distribution/Negative Binomial Distribution



HP 12C:  Combination/Binomial Distribution/Negative Binomial Distribution

Introduction and Formulas

Combination: Find the number of groups out of a possible set of objects.  The order of objects obtained does not matter. 
Store n in R1, x in R0, and p in R2.  Press [ f ] [ R↓]  (CLEAR PRGM), [ R/S ]
Formula:  COMB(n, x)  = n!/(x! * (n-x)!)

Binomial Distribution:  Find number of successes (x) in a fixed number of trials (n). 
Store n in R1, x in R0, and p in R2.  Press [ g ] [ R↓ ] (GTO) 26, [R/S]
Formula:  COMB(n, x) * p^x * (1 – p)^(n – x)

Negative Binomial Distribution:  Find the number of trials (n) needed to obtain a fixed amount of successes (x).
Store x in R1, n in R0, and p in R2.  Press [ g ] [ R↓ ] (GTO) 43, [R/S]
Formula:  COMB(x – 1, n – 1) * p^(n -1) * (1 – p)^((x - 1) - (n – 1))

In the distribution calculations, p is the probability where 0 ≤ p ≤ 1. 
Note: R3 is used as a flag, which will allowed for branching.

STEP
CODE
KEY
Combination


01
0
0
02
44, 3
STO 3
03
45, 1
RCL 1
04
43, 3
N!
05
45, 0
RCL 0
06
43, 3
N!
07
10
÷
08
45, 1
RCL 1
09
45, 0
RCL 0
10
30
-
11
43, 3
N!
12
10
÷
Flag Testing


13
45, 3
RCL 3
14
1
1
15
30
-
16
43, 35
X=0
17
43, 33, 29
GTO 29
18
45, 3
RCL 3
19
2
2
20
30
-
21
43, 35
X=0
22
43, 33, 49
GTO 49
23
33
R↓
24
33
R↓
25
43, 33, 00
GTO 00
Binomial Distribution


26
1
1
27
44, 3
STO 3
28
43, 33, 03
GTO 03
29
33
R↓
30
45, 2
RCL 2
31
45, 0
RCL 0
32
21
Y^X
33
20
*
34
1
1
35
45, 2
RCL 2
36
30
-
37
45, 1
RCL 1
38
45, 0
RCL 0
39
30
-
40
21
Y^X
41
20
*
42
43, 33, 00
GTO 00
Negative Binomial Distribution


43
1
1
44
44, 30, 1
STO- 1
45
44, 30, 0
STO- 0
46
2
2
47
44, 3
STO 3
48
43, 33, 03
GTO 03
49
33
R↓
50
33
R↓
51
45, 2
RCL 2
52
45, 0
RCL 0
53
21
Y^X
54
20
*
55
1
1
56
45, 2
RCL 2
57
30
-
58
45, 1
RCL 1
59
45, 0
RCL 0
60
30
-
61
21
Y^X
62
20
*
63
43, 33, 00
GTO 00

Examples:

Find the number of combinations of groups of 2 out of possible 12 objects. 
12 [STO] 1, 2 [STO] 0, [ f ] [ R↓ ] (CLEAR PRGM)
Result:  66

Binomial Distribution:  Toss a coin 25 times. (trails) What is the probability of tossing 10 heads? (successes)  Assume a fair coin.  The variables n = 25, x = 10, p = 0.5 
25 [ STO ] 1, 10 [ STO ] 0, 0.5 [ STO ] 2, [ g ] [ R↓ ] (GTO) 26 [ R/S ]
Result:  0.10   (0.0974166393)

Negative Binomial Distribution:  Assume a fair coin. What is the probability that the 15th tossed of heads comes on the 25th toss of the coin?  x = 15, n = 25, p = 0.5
25 [STO] 1, 15 [STO] 0, 0.5 [ STO ] 2, [ g ] [ R↓] (GTO) 43 [ R/S ]
Result:  0.12  (0.1168999672)

This blog is property of Edward Shore, 2016.

Python (TI-84 Plus CE) and Swiss Micros DM32: The Integral of y = abs(r * x + s)

Python (TI-84 Plus CE) and Swiss Micros DM32: The Integral of y = abs(r * x + s) The Integral of y = abs(r * x + s) This algor...