Java Array Subtract subtract(double[][] a, double[][] b)

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

Description

Subtracts the two arrays.

License

Open Source License

Exception

Parameter Description
NullPointerException if either input or on of it's elements are null;

Declaration

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

Method Source Code

//package com.java2s;
/*//from  w ww. j av  a2s .  c  o m
 *  Copyright (C) 2013, Peter Decsi.
 * 
 *  This library is free software: you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public 
 *  License as published by the Free Software Foundation, either 
 *  version 3 of the License, or (at your option) any later version.
 * 
 *  This library 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 Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Subtracts the two arrays. The length of the returned array will be
     * equal to the length of the shorter input.
     * 
     * @throws NullPointerException if either input or on of it's elements are null;
     */
    public static double[][] subtract(double[][] a, double[][] b) {
        int size = Math.min(a.length, b.length);
        double[][] result = new double[size][];
        for (int i = 0; i < size; i++)
            result[i] = subtract(a[i], b[i]);
        return result;
    }

    /**
     * Subtracts the two vectors. The length of the returned vector will be
     * equal to the length of the shorter input.
     * 
     * @throws NullPointerException if `a` or `b` is null;
     */
    public static double[] subtract(double[] a, double[] b) {
        int size = Math.min(a.length, b.length);
        double[] result = new double[size];
        for (int i = 0; i < size; i++)
            result[i] = a[i] - b[i];
        return result;
    }
}

Related

  1. subtract(double[] flowFrom, double[] flowTo)
  2. subtract(double[] p1, double[] p2)
  3. subtract(double[] res, double[] subtractor)
  4. subtract(double[] values, double value)
  5. subtract(double[] x, double c)
  6. subtract(double[][] a, double[][] b)
  7. subtract(double[][] dest, double[][] a, double[][] b)
  8. subtract(final double[] a, final double[] b, final double[] c)
  9. subtract(final double[] first, final double[] second)