Java Array Sum Square sumSq(double[] a)

Here you can find the source of sumSq(double[] a)

Description

Returns the sum of squares.

License

Apache License

Parameter

Parameter Description
a the array.

Return

the sum of squares.

Declaration

public static double sumSq(double[] a) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from   ww w  . j a  v a 2  s. c  om*/
     * Returns the sum of squares.
     * 
     * @param a the array.
     * @return the sum of squares.
     */
    public static double sumSq(double[] a) {
        return sumSq(a, 0, a.length);
    }

    /**
     * Returns the sum of squares within a specific range.
     * 
     * @param a the array.
     * @param fromIndex the index of the first element (inclusive).
     * @param toIndex the index of the last element (exclusive).
     * @return the sum of squares.
     */
    public static double sumSq(double[] a, int fromIndex, int toIndex) {
        double sq = 0.0;
        for (int i = fromIndex; i < toIndex; i++) {
            sq += a[i] * a[i];
        }
        return sq;
    }
}

Related

  1. sumOfSquares(double[] vector)
  2. sumOfSquares(double[] vector)
  3. sumOfSquares(int numberOfTerms)
  4. sumOfSquares(Number[] array)
  5. sumSq(double... values)
  6. sumSqual(byte[] b)
  7. sumSquared(double[] data)
  8. sumSquared(double[] data, double term)
  9. SumSquared(Object in)