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

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

Description

subtract

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/**/*from   w  w w.j a  v  a 2  s  .  co m*/
 * Copyright 2004-2006 DFKI GmbH.
 * All Rights Reserved.  Use is subject to license terms.
 *
 * This file is part of MARY TTS.
 *
 * MARY TTS 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, version 3 of the License.
 *
 * 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

public class Main {
    public static double[] subtract(double[] a, double[] b) {
        if (a.length != b.length) {
            throw new IllegalArgumentException("Arrays must be equal length");
        }
        double[] c = new double[a.length];
        for (int i = 0; i < a.length; i++) {
            c[i] = a[i] - b[i];
        }
        return c;
    }

    public static double[] subtract(double[] a, double b) {
        double[] c = new double[a.length];
        for (int i = 0; i < a.length; i++) {
            c[i] = a[i] - b;
        }
        return c;
    }

    public static double[][] subtract(double[][] x, double[][] y) {
        double[][] z = null;

        if (x != null && y != null) {
            int i, j;
            assert x.length == y.length;
            for (i = 0; i < x.length; i++) {
                assert x[i].length == x[0].length;
                assert x[i].length == y[i].length;
            }

            z = new double[x.length][x[0].length];

            for (i = 0; i < x.length; i++) {
                for (j = 0; j < x[i].length; j++)
                    z[i][j] = x[i][j] - y[i][j];
            }
        }

        return z;
    }

    public static float[] subtract(float[] a, float[] b) {
        if (a.length != b.length) {
            throw new IllegalArgumentException("Arrays must be equal length");
        }
        float[] c = new float[a.length];
        for (int i = 0; i < a.length; i++) {
            c[i] = a[i] - b[i];
        }
        return c;
    }

    public static float[] subtract(float[] a, float b) {
        float[] c = new float[a.length];
        for (int i = 0; i < a.length; i++) {
            c[i] = a[i] - b;
        }
        return c;
    }
}

Related

  1. arraySubtract(double[] x1, double[] x2)
  2. arraySubtract(final Double[] first, final Double[] second)
  3. subtract(byte[] a, byte[] b)
  4. subtract(double[] a, double[] b)
  5. subtract(double[] a, double[] b)
  6. subtract(double[] a, double[] b)
  7. subtract(double[] accumulator, double[] values)
  8. subtract(double[] array, double a)
  9. subtract(double[] array, double value)