(11-20-2015 01:19 PM)Dieter Wrote: BTW, it seems that the program titled "Distribución Polinomial" actually calculates the multinomial distribution (es: distribución multinomial). Since I am not sure about the correct Spanish term: is there a difference between these two expressions or do they refer to the same distribution? If yes: the multinomial distribution can be calculated much easier and without using so many registers.
OK, here is a version that features some advantages:
- Usage is quite straightforward. No need to prestore values in registers or calculate sums manually.
- Uses merely two registers instead of eleven.
- Number k of events can be anything between 1 and ...infinity
- Erroneous data entry can be corrected by re-entering with a negative frequency x.
- Despite all this: shorter. Could be even shorter (not much more than 20 lines) without the error recovery function (see below)
Here is the listing:
Code:
M001 LBL M
M002 CLSTK
M003 STO N n=0
M004 e^x
M005 STO P p=1
M006 ALL
M007 CLSTK
M008 VIEW N show accumulated n
M009 x=0? zero or no entry?
M010 GTO M027 jump to probability calculation
M011 x<>y
M012 STO+ N n := n + x_i
M013 SGN
M014 x<>y save sign(x_i)
M015 LASTx
M016 ABS
M017 y^x
M018 LASTx
M019 !
M020 ÷ p_i^x_i / x_i!
M021 x<>y if xi was negative this is -1 (instead of 1 else)
M022 y^x which turns this into its reciprocal
M023 STOx P update product
M024 GTO M006
M025 RCL N
M026 !
M027 STOx P calculate probability
M028 FIX 6
M029 RCL P return result in X
M030 VIEW P and display labelled output
M031 GTO M001 start a new calculation with R/S
Here is an example using the data from your (Pedro's) PDF:
Code:
x1 = 2 p1 = 0,25
x2 = 2 p2 = 0,25
x3 = 5 p3 = 0,25
x4 = 3 p4 = 0,25
[XEQ] M [ENTER]
N= 0 // Data is entered by
2 [ENTER] 0,25 [R/S] // x_i [ENTER] p_i [R/S]
N= 2
2 [ENTER] 0,25 [R/S]
N= 4
5 [ENTER] 0,5 [R/S]
N= 9 // oops... wrong data
-5 [ENTER] 0,5 [R/S] // re-enter with negative x
N= 4 // and it gets removed
5 [ENTER] 0,25 [R/S]
N= 9
3 [ENTER] 0,25 [R/S]
N= 12
[R/S] // data complete, simply press [R/S] or 0 [R/S]
P= 0,009913 // result
Hmmm... I just got another idea. Maybe this could be done with the Σ+ key using a sum of logs instead of a product... *8)
Edit: Yes, this will also work:
Code:
M001 LBL M
M002 CLΣ
M003 ALL
M004 Σx
M005 STO N
M006 CLSTK
M007 VIEW N
M008 x=0?
M009 GTO M030
M010 LN
M011 x<>y
M012 SGN
M013 STO N save sign(x_i)
M014 LASTx * x_i
M015 x = abs(x_i)
M016 x
M017 LASTx
M018 ENTER
M019 R↓
M020 !
M021 LN
M022 -
M023 R↑
M024 RCLx N multiply
M025 x<>y both values
M026 RCLx N by +1 or -1
M027 x<>y so that this
M028 Σ+ Σ+ may become a Σ-
M029 GTO M003
M030 Σx
M031 !
M032 LN
M033 Σy
M034 +
M035 e^x
M036 STO P
M037 FIX 6
M038 VIEW P
M039 GTO M001
Program usage is the same as before. The code uses only logs of the factorial function (both "!" are followed by a "LN") so that this approach may be especially useful for calculators with lnΓ function, thus avoiding potential overflow problems.
Dieter