Post Reply 
Means: geometric, weighted, harmonic
12-23-2017, 11:20 AM (This post was last modified: 01-04-2018 10:32 AM by salvomic.)
Post: #1
Means: geometric, weighted, harmonic
Here there is a simple program to calculate some means, given lists of values.
• gmean Geometric mean of {list1} (all numbers in the list must be >0)
• wmean Weighted mean of {list1} with weights {wlist}
• hmean Harmonic mean of {list1} (all numbers must be >0)

Enjoy!

Salvo M.

Code:

// Geometric mean
// list1 mustn't have 0 and must contain positive numbers
EXPORT gmean(list1)
BEGIN
RETURN surd(ΠLIST(list1),SIZE(list1));
END;

// Weighted mean
// list1 items, wlist weights
EXPORT wmean(list1, wlist)
BEGIN
RETURN ΣLIST(list1*wlist)/ΣLIST(wlist);
END;

// Harmonic mean
// list1 mustn't contain 0
EXPORT hmean(list1)
BEGIN
RETURN (ΣLIST((list1)^(-1)))^(-1)*SIZE(list1);
END;

EDIT:: thanks to Carlos29pz for info: I didn't remember that we can use the already present command mean(list1, list2) to get weighted mean, so please, use my program only for geometric and harmonic means, since those command won't be built-in the Prime.

EDIT 2 :: see also the thread Means API by StephenG1CMZ with some other means

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)