0 Replies - 1745 Views - Last Post: 09 April 2012 - 07:20 AM

#1 Ryano121   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1461
  • View blog
  • Posts: 3,289
  • Joined: 30-January 11

Calculate the Quadratic Mean

Posted 09 April 2012 - 07:20 AM

Description: See Example Usage in snippetThe quadratic mean is a statistical measure of the magnitude of a varying quantity. It is especially useful when variates are positive and negative.
public class Means
{
    // Returns the quadratic mean (or Root Mean Square) of a data set
    public static double quadraticMean(double[] data)
    {
	double sum = 0;
	
	for(int i = 0; i < data.length; i++)
	{
	    sum += Math.pow(data[i], 2);
	}
	
	return Math.sqrt(sum / data.length);
    }

    public static void main(String[] args)
    {
	double[] x = { 2, 3, 4, 5, 6, 8, 10, 11.53542 };

	System.out.println("Quadratic Mean = " + Means.quadraticMean(x));
    }
}

// OUTPUT

// Quadratic Mean = 6.955806159033617


Is This A Good Question/Topic? 0
  • +

Page 1 of 1