Formula for computing standard deviation

Does anyone out there have a formula for computing Standard deviation for a set of given numbers.

P.S. This formula can not use any arrays, and also the numbers  will becoming from a file.
Who is Participating?
I wear a lot of hats...


Lets assume that we have a file which is a text file and each line contains one data (you can easily modify this if you want):

The formula is:

  mean = SumOf(x1, x2, ..., xN) / N;
  variance = SumOf((x[i]-mean)^2/(N^2));
  stddev = sqrt(variance);

function StdDev(FileName : string):real;
  mean : real;
  nofitems : integer;
  F : text;
  S : string;
  variance : real;
  AssignFile(F, FileName); Reset(F);
  // first compute the mean of the table
  nofitems := 0; mean := 0;
  while not eof(F) do
    readln(F, S);
    mean := mean + StrToFloat(S);
  // divide total by number of items
  mean  := mean / nofitems;
  AssignFile(F, FileName); Reset(F);
  // then compute the variance
  variance := 0;
  while not eof(F) do
    readln(F, S);
    variance := variance + sqr(StrToFloat(S) - mean);
  // normalize it
  variance := variance / sqr(nofitems);
  result := sqrt(Result); // std is the square root of variance

See you around friend!  

Experts Exchange Solution brought to you by

Your issues matter to us.


Start your 7-day free trial

From novice to tech pro — start learning today.