Solved

Formula for computing standard deviation

Posted on 1998-02-14
1
1,196 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

10 Experts available now in Live!

Get 1:1 Help Now