Here you can find the source of sum(double[] a, double[] b)
Parameter | Description |
---|---|
a | vector |
b | vector |
public static double[] sum(double[] a, double[] b)
//package com.java2s; /*//from ww w . j a v a 2s .c o m * Copyright 2014 Vasya Drobushkov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * sum of two vectors * * @param a * vector * @param b * vector * @return new vector = a + b */ public static double[] sum(double[] a, double[] b) { double[] result = new double[a.length]; for (int i = 0; i < a.length; i++) { result[i] = a[i] + b[i]; } return result; } /** * sum of two matrices * * @param a * matrix * @param b * matrix * @return new matrix = a + b */ public static double[][] sum(double[][] a, double[][] b) { double[][] result = new double[a.length][a[0].length]; for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { result[i][j] = a[i][j] + b[i][j]; } } return result; } }