[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

*Subject*: Re: geometric mean?*From*: Craig Markwardt <craigmnet(at)cow.physics.wisc.edu>*Date*: 17 Sep 2000 07:03:20 -0500*Newsgroups*: comp.lang.idl-pvwave*Organization*: U. Wisc. Madison Physics -- Compact Objects*References*: <8p8pni$b2v$1@nnrp1.deja.com> <8p9f67$4rq$1@nnrp1.deja.com>*Reply-To*: craigmnet(at)cow.physics.wisc.edu*Xref*: news.doit.wisc.edu comp.lang.idl-pvwave:21421

Andrew <noymer@my-deja.com> writes: > I have no response so I assume the answer is to > roll your own. > > I did: > > FUNCTION GEOMEAN, arr > RETURN, EXP(TOTAL(ALOG(arr))/N_ELEMENTS(arr)) > END > > - Andrew I am back from a long trip, so I'll bat a little cleanup here. Andrew you asked about negative values of ARR. I think it's fair to say that the geometric mean is not meaningful (no pun intended) for negative values. Therefore I think it would be simplest to take the absolute value, like this: FUNCTION GEOMEAN, arr RETURN, EXP(TOTAL(ALOG(ABS(arr)))/N_ELEMENTS(arr)) END To go on to your more general question, the logarithm *is* in fact defined for negative values, unfortunately it's a complex number. Also, it's not unique. To prove that to yourself consider the fact that Y=EXP(I*X) is an oscillating function like COS and SIN, so a multitude of X values will give the same Y value (here I is the complex number COMPLEX(0,1)). If you really wanted to perform the geometric mean of negative numbers then be sure to cast them to the complex type before taking the logarithm. There will always be some ambiguity about the sign just as SQRT(X) can formally be either positive or negative. Craig -- -------------------------------------------------------------------------- Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response --------------------------------------------------------------------------

**References**:**geometric mean?***From:*Andrew

**Re: geometric mean?***From:*Andrew

- Prev by Date:
**Re: Minor ticks beyond last xtickv?** - Next by Date:
**Re: Vectorization question** - Prev by thread:
**Re: geometric mean?** - Next by thread:
**DISPLAY bug fixed** - Index(es):