Java Array Subtract subtract(final double[] v1, final double[] v2)

Here you can find the source of subtract(final double[] v1, final double[] v2)

Description

subtract

License

Open Source License

Declaration

public static double[] subtract(final double[] v1, final double[] v2) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 Vienna University of Technology.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from  w ww.j a  v  a  2  s . c  o  m
 * Martin Fleck (Vienna University of Technology) - initial API and implementation
 *
 * Initially developed in the context of ARTIST EU project www.artist-project.eu
 *******************************************************************************/

public class Main {
    private static final String VECTORS_DIFFERENT_LENGTHS = "Vector v1 and v2 have different lengths";

    public static double[] subtract(final double[] v1, final double[] v2) {
        if (v1.length != v2.length) {
            throw new RuntimeException(VECTORS_DIFFERENT_LENGTHS);
        }

        final double[] result = new double[v1.length];
        for (int i = 0; i < result.length; i++) {
            result[i] = v1[i] - v2[i];
        }

        return result;
    }
}

Related

  1. subtract(double[][] a, double[][] b)
  2. subtract(double[][] a, double[][] b)
  3. subtract(double[][] dest, double[][] a, double[][] b)
  4. subtract(final double[] a, final double[] b, final double[] c)
  5. subtract(final double[] first, final double[] second)
  6. subtract(final double[] vector1, final double[] vector2)
  7. subtract(float a[][][], float b[][][])
  8. subtract(float[] dividend, float[] divisor)
  9. subtract(int a, int[] b)