Java Array Sum sumSquared(double[] a)

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

Description

sum Squared

License

Open Source License

Declaration

public static double sumSquared(double[] a) 

Method Source Code

//package com.java2s;
/* /*  w w  w.  j  a  va  2  s. c  om*/
 * Copyright (C) 2015 ikonstas
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Map;

public class Main {
    public static double sumSquared(double[] a) {
        double result = 0.0;
        for (int i = 0; i < a.length; i++) {
            result += a[i] * a[i];
        }
        return result;
    }

    public static double sumSquared(Map<Integer, Double> a) {
        double result = 0.0;
        for (Double v : a.values())
            result += v * v;
        return result;
    }
}

Related

  1. sumOfMinimum(double[] a, double[] b)
  2. sumOfProducts(double[]... nums)
  3. sumOverVector(float[] a)
  4. sumProd(double[] v1, double[] v2, int i_, int n_)
  5. sumRightShifts(int num, int... shifts)
  6. sumToDouble(float[] array)
  7. sumToLong(byte[] array)
  8. sumUpArray(int[] array)
  9. sumValues(double[] vector)