Your question, your audience. Choose who sees your identityâ€”and your questionâ€”with question security.

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.

P.S. This formula can not use any arrays, and also the numbers will becoming from a file.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Tackle projects and never again get stuck behind a technical roadblock.

Join Now
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;

var

mean : real;

nofitems : integer;

F : text;

S : string;

variance : real;

begin

AssignFile(F, FileName); Reset(F);

// first compute the mean of the table

nofitems := 0; mean := 0;

while not eof(F) do

begin

readln(F, S);

mean := mean + StrToFloat(S);

Inc(nofitems);

end;

// divide total by number of items

mean := mean / nofitems;

CloseFile(F);

AssignFile(F, FileName); Reset(F);

// then compute the variance

variance := 0;

while not eof(F) do

begin

readln(F, S);

variance := variance + sqr(StrToFloat(S) - mean);

Inc(nofitems);

end;

// normalize it

variance := variance / sqr(nofitems);

CloseFile(F);

result := sqrt(Result); // std is the square root of variance

end;

See you around friend!

Igor