/**
* This program calculates the mean and the standard deviation of n numbers
* in a Vector
*
* @version $Id: MathClass.java,v 1.2 1998/09/13 05:48:29 tfm1584 Exp tfm1584 $
*
* @author Tom M
*
* Revisions:
* $Log: MathClass.java,v $
* Revision 1.2 1998/09/13 05:48:14 tfm1584
* forgot to take square root of std. dev. result
*
* Revision 1.1 1998/09/13 03:51:49 tfm1584
* Initial revision
*
*/
import java.util.Vector;
public class MathClass {
/**
* The constructor
*/
public MathClass( ) {
}
/**
* this calculates the mean of all of the doubles - it sums all of the
* numbers then divides the result by the total number of elements
*
* @param meanNums the Vector of Doubles
*
* @return the average of the numbers
*/
public double calculateMean( Vector meanNums ) {
double total = 0;
Double dValue; // Double from vector before converting to double
int length = meanNums.size();
for ( int i = 0; i < length; i++ ) {
dValue = (Double)meanNums.elementAt( i );
total += dValue.doubleValue();
}
return (total/length);
}
/**
* This calculates the standard deviation of the doubles. It adds up all
* of the squares of the differences of the numbers from the mean, then
* takes the square root of the total over the number of elements - 1
*
* @param stddevNums the numbers to find the std. dev. of
* @param avg the mean of the numbers
*
* @return the calculated std. dev. of all of the numbers
*/
public double calculateStdDev( Vector stddevNums, double avg ) {
double total = 0;
Double dValue; // Double from vector before converting to double
int length = stddevNums.size();
for ( int i = 0; i < length; i++ ) {
dValue = (Double)stddevNums.elementAt( i ) ;
total += Math.pow( (dValue.doubleValue() - avg), 2.0 ) ;
}
return ( Math.sqrt( total / (length - 1 ) ));
}
}