Calculates the power in a sample as sum of the squares of the absolute values of all samples. - Java Collection Framework

Java examples for Collection Framework:Array Algorithm

Description

Calculates the power in a sample as sum of the squares of the absolute values of all samples.

Demo Code


//package com.java2s;

public class Main {
    /**//from w w w  .j  a va 2  s.  com
     * Calculates the power in a sample as sum of the squares of the absolute values of all samples.
     * @param sample
     * @return
     */
    public static double getPower(double[] sample) {
        double power = 0;
        for (int i = 0; i < sample.length; i++) {
            power += Math.pow(Math.abs(sample[i]), 2);
        }
        return power;
    }
}

Related Tutorials