Jun. 28th, 2005

plonq: (Masturbatory Mood)
The height of drama in my life lately is that somebody stole my usual parking spot this morning.

Fortunately he was the only vehicle parked on that deck of the parking garage at the time, so I had little trouble finding an alternate spot.

I suppose I might have been momentarily vexed if I'd tried, but in truth I couldn't dredge up enough caring to be suitably miffed.

Deviations

Jun. 28th, 2005 10:41 am
plonq: (Creative mood)
For no apparent reason I decided that I wanted to calculate the standard deviation for a column of numbers I'd gathered for somebody.  It's been years since I took any statistics courses and I couldn't remember the formula.

I applied what I could remember of the subject, and I wrote the following snippet of code:

do eStem = 1 to Elements
    Variance = Variance + ( ( Element.eStem - Mean ) ^ 2 ) / Elements )
end

Standard_Deviation = Variance / 3
do until trunc( Standard_Deviation^2, 15 ) = Variance
    Standard_Deviation = .5 * ( Standard_Deviation + ( Variance / Standard_Deviation ) )
end


(Yes, sadly this stupid language doesn't have a square root function, so I had to derive it using Newton's method.)

Only after I'd done this did it occur to me that Excel has a StdDev function that might have worked.  I tried that... and it gave me a different answer.  Huh? 

My immediate assumption was that Excel must be wrong. 

Moments later reason set in, and I realized that I had most likely left something out of my equation.  After a quick trip to Mister Internet, I revised my program slightly to read:

do eStem = 1 to Elements
    Variance = Variance + ( ( Element.eStem - Mean ) ^ 2 ) / ( Elements - 1 ) )
end


Suddenly the world is a joyous place again.  I'm not sure why I'm happy that I managed to write a program to replicate what Excel does for me automatically, but it's kind of like whittling a working automobile out of a block of pine.  It may not be practical, but at least it's yours.

[Edit: Just for giggles I expanded it to calculate the Nth root, and turned it into a self-contained little module that I can import into any future programs that I write in this language.]

August 2025

S M T W T F S
     12
3456789
10111213141516
171819202122 23
24252627282930
31      

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Mar. 24th, 2026 07:55 am
Powered by Dreamwidth Studios