John's comment about numerical stability is the wrong way around.  sd is 
clearly more stable than sd2.

   a =: i:5
   b =: 100000000000000+i:5
   sd a
3.31662
   sd b
3.31662

   sd2 a
3.31662
   sd2 b
0j1.13112e6

Fraser

----- Original Message ----- 
From: "John Randall" <[email protected]>
To: "General forum" <[email protected]>
Sent: Saturday, March 14, 2009 6:56 AM
Subject: Re: [Jgeneral] J with APL


> Don Watson wrote:
>> Could someone tell me how I put down a one line J expression that
>> calculates the standard deviation of its right argument - assumed for the
>> moment to be a vector - without naming the argument in the expression.
>
> Calculating it using the textbook definition:
>
> sd=:[: %: +/@:*:@:(- +/ % #) % <:@#
>
> This uses deviates about the mean.  It is less numerically stable than
>
> ssq=:+/@:*:
> sqs=:*:@:(+/)
> sd2=:[: %: ((#*ssq)-sqs)% #*<:@#
>
> which uses the sum of squares and the square of the sum.  It is broken out
> here to show these operations, but can obviously be put on one line.
>
> Best wishes,
>
> John
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm 

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to