Java Vector vectorDiff(final double[] vecOne, final double[] vecTwo)

Here you can find the source of vectorDiff(final double[] vecOne, final double[] vecTwo)

Description

Substract two vectors.

License

Apache License

Parameter

Parameter Description
vecOne a parameter
vecTwo a parameter

Declaration

public static double[] vectorDiff(final double[] vecOne, final double[] vecTwo) 

Method Source Code

//package com.java2s;
/*//from   w  ww .j a  va 2  s  . co  m
 * Copyright 2016 Langhammer, Tim | Earth >> Europe >> Potsdam |
 * {@literal @}<a href="mailto:tlhammer@mailbox.org" alt="email">mail</a> |
 * "Tolerance first".
 *
 * 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 {
    /**
     * Substract two vectors.
     * <p/>
     * @param vecOne
     * @param vecTwo
     * @return
     */
    public static double[] vectorDiff(final double[] vecOne, final double[] vecTwo) {
        if (vecOne == null || vecTwo == null) {
            throw new IllegalArgumentException("vector 'vecOne' or 'vecTwo' == null!");
        }
        if (vecOne.length != vecTwo.length) {

            throw new IllegalArgumentException(
                    "The vectors differs in length!( " + vecOne.length + " != " + vecTwo.length);
        }
        double[] ret = new double[vecOne.length];

        for (int i = 0; i < ret.length; i++) {
            ret[i] = vecOne[i] - vecTwo[i];
        }
        return ret;
    }
}

Related

  1. vector_dot(double[] vec1, double[] vec2)
  2. vector_norm(double[] vec)
  3. vector_sum(double[] v, double[] w)
  4. vectorAbsoluteValue(double X, double Y, double Z)
  5. vectorCos(int[] d1, int[] d2)
  6. vectorDir(int vert, int horiz)
  7. vectorDistance(double[] vec1, double[] vec2, double power)
  8. vectorIndexToUpperTriangularIndices(int numberOfRows, int index)
  9. vectorKLDivergence(double v1[], double v2[])