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;

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

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