Here you can find the source of sum(double[] a, double[] b)
Parameter | Description |
---|---|
a | first vector |
b | second vector |
Parameter | Description |
---|---|
IllegalArgumentException | if the two vector don't have the same length |
public static double[] sum(double[] a, double[] b)
//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; } }