Java Array Sum Square sumSquares(double[] data)

Here you can find the source of sumSquares(double[] data)

Description

Sums the squares of all components; also called the energy of the array.

License

Open Source License

Declaration

public static double sumSquares(double[] data) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from   w  ww . jav  a 2  s .c  om*/
     * Sums the squares of all components;
     * also called the energy of the array.
     */
    public static double sumSquares(double[] data) {
        double ans = 0.0;
        for (int k = 0; k < data.length; k++) {
            ans += data[k] * data[k];
        }
        return (ans);
    }

    /**
     * Sums the squares of all components;
     * also called the energy of the array.
     */
    public static double sumSquares(double[][] data) {
        double ans = 0.0;
        for (int k = 0; k < data.length; k++) {
            for (int l = 0; l < data[k].length; l++) {
                ans += data[k][l] * data[k][l];
            }
        }
        return (ans);
    }

    /**
     * Sums the squares of all components;
     * also called the energy of the array.
     */
    public static int sumSquares(int[] data) {
        int ans = 0;
        for (int k = 0; k < data.length; k++) {
            ans += data[k] * data[k];
        }
        return (ans);
    }

    /**
     * Sums the squares of all components;
     * also called the energy of the array.
     */
    public static int sumSquares(int[][] data) {
        int ans = 0;
        for (int k = 0; k < data.length; k++) {
            for (int l = 0; l < data[k].length; l++) {
                ans += data[k][l] * data[k][l];
            }
        }
        return (ans);
    }
}

Related

  1. SumSquared(Object in)
  2. sumSquaredError(double[] a, double[] b)
  3. sumSquareDev(double[] values, double target)
  4. sumSquareDoubleArray(double[] v)
  5. sumSquares(double[] aArray)
  6. sumSquares(final float[] a)
  7. sumSquares(float[] in)
  8. sumValuesSquared(double[] vector)