(19C/29C) (k-)Permutations, Combinations, Linear Regression and Pseudo-random number
|
01-15-2020, 01:42 PM
(This post was last modified: 01-16-2020 05:20 PM by Archilog.)
Post: #1
|
|||
|
|||
(19C/29C) (k-)Permutations, Combinations, Linear Regression and Pseudo-random number
Here is a set of routines in 96 steps to add to your HP-19C, HP-29C or HP-29E.
The three first routines (steps 01 to 37) 1, 2 and 3 compute: - the factorial of an integer between 0 and 69 - or number of permutations of n elements without repetition(*); - the number of k-permutations from a set of n elements; - the number of combinations of k elements from a set of n elements. In this program factorials are computed into the k-permutations routine therefore the two routines (steps 01 to 25) are needed; for the same reason computing combinations needs the whole set (steps 01 to 37); this program does not suit for large N and small K - see below for other references. Please note that input values are not checked for validity. (*): Number of permutations of n elements with repetition is given by n^k. Code:
Examples: [0] [GSB] [1]: 0!=1 [1] [2] [GSB] [1]: 12!=479001600 [8] [ENTER] [3] [GSB] [2]: P(8,3)=336 [7] [8] [ENTER] [6] [GSB] [3]: C(78,6)=256851595 Here is a longer version to compute Factorials, Permutations and Combinations with bigger n and smaller k. Another interesting way to proceed should be to use common logarithms like in this program for HP-25. The fourth routine (steps 38 to 88) computes a linear regression (y=a1.x + a0) with a0, a1 and coefficient of determination r² respectively in register 3, 4 and 5 from a set of statistical datas (registers 10 to 15); then the program waits for a new variable x to predict y. Code:
Example (from HP25 Applications Programs): An eccentric professor of numerical analysis wakes up one morning and feels feverish. A search through his medicine cabinet reveals one oral thermometer which, unfortunately, is in degrees centigrade, a scale he is not familiar with. As he stares disconsolately out his window, he spies the outdoor thermometer affixed to the windowframe. This thermometer, however, will not fit comfortably into his mouth. Still, with some ingenuity... The professor suspects that the relationship is F = a1 C + a0. If he can get a few data pairs for F and C, he can run a linear regression program to find a1 and a0, then convert any reading in °C to °F through the equation. So tossing both thermometers into a sink of lukewarm water, he reads the following pairs of temperatures as the water cools: Code: C | 40.5 | 38.6 | 37.9 | 36.2 | 35.1 | 34.6 | If the relationship is indeed F = a1 C + a0, what are the values for a1 and a0? What is the coefficient of determination? Solution: In RUN mode, press [f] [Σ], 104.5 [ENTER] 40.5 [Σ+] 102 [ENTER] 38.6 [Σ+] 100 [ENTER] 37.9 [Σ+] 97.5 [ENTER] 36.2 [Σ+] 95.5 [ENTER] 35.1 [Σ+] 94 [ENTER] 34.6 [Σ+] [GSB] [4] The calculator displays in engineering notation: - r² (961.3 -03); - a0 (125.8 00); - a1 (171.5 00), waiting for a new x. Suppose the professor puts the centigrade thermometer in his mouth and finds he has a temperature of 37°C. Should he be worried? Press 37 [R/S] ---------------------> 98.65°F (98.65 00) It looks he is safe. You can compute another value by pressing [GSB] [4], entering a new variable x and pressing [R/S]. Pseudo-random number is useful in statistics, here is a quick code to fill the program zone and generate some; you only need to enter a seed [0 ; +1] in X register and to press [GSB] [5] (steps 89 to 96): Code:
Examples: 0.5 in X register will generate sequence 0.41, 0.58, 0.45, 0.51, 0.11, 0.26, etc. Edition: two useless steps were removed from first routine, two links were added. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)