Post Reply 
Geometric and weighted mean
12-23-2017, 10:33 AM (This post was last modified: 12-23-2017 07:35 PM by salvomic.)
Post: #9
RE: Geometric and weighted mean
Could this code be good?
No error correction (for 0, negative numbers) in it.

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;

With the Carlos' lists list1={5.2, 8.2,7.4,5.7}, wlist={3,1,2,4}:

mean(list1) = 6.625
median(list1) = 6.55

gmean(list1) = 6.51224817722
wmean(list1, wlist) = 6.14
hmean(list1) = 6.40171419012

Question for Bernard: are there those means in XCAS?

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.

∫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 


Messages In This Thread
Geometric and weighted mean - salvomic - 12-22-2017, 10:13 PM
RE: Geometric and weighted mean - salvomic - 12-23-2017, 07:46 AM
RE: Geometric and weighted mean - Arno K - 12-23-2017, 08:57 AM
RE: Geometric and weighted mean - salvomic - 12-23-2017, 09:20 AM
RE: Geometric and weighted mean - Arno K - 12-23-2017, 09:29 AM
RE: Geometric and weighted mean - salvomic - 12-23-2017, 09:31 AM
RE: Geometric and weighted mean - salvomic - 12-23-2017 10:33 AM
RE: Geometric and weighted mean - DrD - 12-23-2017, 11:42 AM
RE: Geometric and weighted mean - salvomic - 12-23-2017, 11:51 AM
RE: Geometric and weighted mean - salvomic - 12-23-2017, 05:25 PM
RE: Geometric and weighted mean - salvomic - 12-24-2017, 08:33 AM
RE: Geometric and weighted mean - salvomic - 01-04-2018, 05:24 PM
RE: Geometric and weighted mean - Joe Horn - 01-20-2022, 08:33 PM



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