comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: geometric mean?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: geometric mean? [message #21746 is a reply to message #21631] Sun, 17 September 2000 00:00 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
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
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Minor ticks beyond last xtickv?
Next Topic: Re: Vectorization question

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 00:58:07 PDT 2025

Total time taken to generate the page: 1.28426 seconds