Java Array Sum sum(double[] a, double[] b)

Here you can find the source of sum(double[] a, double[] b)

Description

Returns the sum of two vectors

License

Open Source License

Parameter

Parameter Description
a first vector
b second vector

Exception

Parameter Description
IllegalArgumentException if the two vector don't have the same length

Return

the sum

Declaration

public static double[] sum(double[] a, double[] b) 

Method Source Code

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

public class Main {
    /**/*from  w w w  . j av a2  s  .  co m*/
     * Returns the sum of two vectors
     *
     * @param a first vector
     * @param b second vector
     * @return the sum
     * @throws IllegalArgumentException if the two vector don't have the same length
     */
    public static double[] sum(double[] a, double[] b) {
        if (a.length != b.length) {
            throw new IllegalArgumentException(
                    "Error computing sum in Utilities.sum: arrays should have the same length");
        }
        double[] sum = new double[a.length];
        for (int i = 0; i < a.length; i++) {
            sum[i] = a[i] + b[i];
        }
        return sum;
    }
}

Related

  1. sum(double... a)
  2. sum(double... values)
  3. sum(double... values)
  4. sum(double[] a)
  5. sum(double[] a)
  6. sum(double[] a, double[] b)
  7. sum(double[] aArray)
  8. sum(double[] addends)
  9. sum(double[] array)