Saturday, January 13, 2024

TI-30Xa Algorithms: Probability

TI-30Xa Algorithms:  Probability



Introduction


Even when a calculator isn't (technically) programmable, algorithms can be applied to scientific and financial calculations.


The calculations take numerical arguments that are stored in the TI-30Xa's three memory slots:  M1, M2, and M3.  Store amounts into the memory registers by the [ STO ] key.  


Careful:  For the solar versions of the TI-30Xa, do not press the [ON/AC] button as doing so clears the memory registers.


The registers used:


M1 = n 

M2 = k 

M3 = p 



Repeated Combinations


nHk = (n + k -1)Ck = (n + k - 1)! ÷ (k! × (n - 1)!)


Registers:


M1:  n = number of objects

M2:  k = number of objects chosen in the population


nHk = number of combinations of picking k from n objects, assuming repeats are allowed


Algorithm:


[ ( ] [ RCL ] 1 [ + ] [ RCL ] 2 [ - ] 1 [ ) ] [ 2nd ] (nCr) [ RCL ] 2 [ = ]


Example:


M1: n = 50

M2: k = 5


Result:  3,162,510



Binomial Probability Distribution


Prob(k) = nCk × p^k × (1 - p)^(n - k) = n! ÷ (k! × (n - k)!) × p^k × (1 - p)^(n - k) 


Registers:


M1:  n = number of trials

M2:  k = number of successes

M3:  p = probability of success (in decimal; i.e. enter 0.30 for 30%)


Prob =  probability of k successes out of n trials with a success probability p


Algorithm:  


[ RCL ] 1 [ 2nd ] (nCr) [ RCL ] 2 [ × ] [ RCL ] 3 [ y^x ] [ RCL ] 2 [ × ] [ ( ] 1 [ - ] [ RCL ] 3  [ ) ] [ y^x ] [ ( ] [ RCL ] 1 [ - ] [ RCL ] 2 [ ) ] [ = ] 


Example:


M1: n = 50

M2: k = 5

M3: p = 0.8


Result:  2.442763967 × 10^-26



Geometric Probability Distribution


Prob(k) = (1 - p)^(k - 1) × p


Registers:


M2:  k = number of failures before the first success

M3:  p = probability of success (in decimal) 


Prob = probability of a event taking k trials before the first success


Algorithm:


[ ( ] 1 [ - ] [ RCL ] 3 [ ) ] [ y^x ] [ ( ] [ RCL ] 2 [ - ] 1 [ ) ] [ × ] [ RCL ] 3 [ = ]


Example:


M2: k = 5

M3: p = 0.8


Result:  0.00128



A Simple Pseudorandom Number Generator


The TI-30Xa does not have a random number function.  To generate random numbers, a pseudorandom number generator algorithm must be used in the form of:


x_n+1 = f(x_n)


where x_0 is the initial value, known as the seed value.  



A simple pseudorandom  number generator to generate numbers between 0 and 1 is:


x_n+1 = frac(997 × x_n + π)



Algorithm:


With x_n in display:

[ × ] 997 [ + ] [ π ] [ = ] 

[ - ] the integer part of the number in the display [ = ]


Result:  x_n+1.   


There is no fraction part or integer part functions are not available on the TI-30Xa.  



Example:   


Starting seed:   0.7896   


[ × ] 997 [ + ] 

[ π ] [ = ]        Display:  799.3457927

[ - ] 799 [ = ]  Display:  0.345792654


[ × ] 997 [ + ] 

[ π ] [ = ]        Display:  347.8968683

[ - ] 347 [ = ]  Display:  0.896868283


[ × ] 997 [ + ] 

[ π ] [ = ]        Display:  897.3192706

[ - ] 897 [ = ]  Display:  0.319270625


[ × ] 997 [ + ] 

[ π ] [ = ]        Display:  321.4544059

[ - ] 321 [ = ]  Display:  0.454405908


and so on...


The random numbers with the starting seed 0.7896 are:

0.345792654

0.896868283

0.319270625

0.454405908


Take as many decimal points as you wish.  




If you enjoy this post, I will consider making a series using the TI-30Xa calculator (and similar simple scientific calculators).  Until next time,


Eddie 


All original content copyright, © 2011-2024.  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.