Solved

Formula for computing standard deviation

Posted on 1998-02-14
1
1,194 Views
Last Modified: 2008-03-17
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.
0
Comment
Question by:delbrad
1 Comment
 
LVL 5

Accepted Solution

by:
inter earned 50 total points
ID: 1359196
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
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now