Mean
Posted in 1994
Folks, I made the mistake of asking my brother the Topology Phud for help on this. Turns out there are 5 different means. I settled for the geometric mean which is calculated as the product of all values to the 1/(number_of_values)th. Here is a quick routine that demonstrates this technique. It gives a 13 as the average and a 6 as the mean - which is what I wanted. It is somewhat limited to small values by the precision of db_i - but then feel free to change that. This routine also demonstratres why I wanted a mean and not an average. I think I also now understand Jonathan Chandross's suggestion. MAIN DEFINE a ARRAY[30] OF INTEGER, non_zero_val, MAX_VAL, i, j SMALLINT, db_i FLOAT(16) LET a[1] = 0 LET a[2] = 3 LET a[3] = 0 LET a[4] = 0 LET a[5] = 5 LET a[6] = 2 LET a[7] = 2 LET a[8] = 0 LET a[9] = 0 LET a[10] = 0 LET a[11] = 40 LET a[12] = 37 LET a[13] = 3 LET a[14] = 0 LET a[15] = 6 LET a[16] = 0 LET a[17] = 52 LET a[18] = 3 LET a[19] = 0 LET a[20] = 6 LET a[21] = 3 LET MAX_VAL = 21 # number of array elements LET db_i = 1 # init to one since we are going to mult. FOR i = 1 TO MAX_VAL IF a[i]> 0 THEN LET non_zero_val = non_zero_val + 1 LET db_i = db_i*a[i] # mutliply it in. LET j = j + a[i] # for kicks (the average) END IF END FOR # we now have db_i which is a product of all non-zero values, and # non_zero_val which is the number of non-zero_values LET j = j/non_zero_val DISPLAY "Average :", j FOR i = 1 TO 9999 IF i**non_zero_val > db_i THEN EXIT FOR END IF END FOR LET i = i - 1 DISPLAY "Geometric mean: ", i END MAIN j. _____________________________________________________________________________ Jack Parker | Hewlett Packard, BSMC Boise, Idaho, USA| If you put all of the lawyers in jparker@hpbs3645.boi.hp.com | this country end to end, (208) 396-5388 (W) (208) 384-1623 (H) | it would be a good thing. _____________________________________________________________________________ Any opinions expressed herein are my own and not those of my employers. _____________________________________________________________________________