Here you can find the source of subtract(double[] first, double[] second)
Parameter | Description |
---|---|
first | a parameter |
second | a parameter |
public static double[] subtract(double[] first, double[] second) throws Exception
//package com.java2s; /******************************************************************************* * Copyright 2013 Karlsruhe Institute of Technology. This Work has been partially supported by the EIT ICT Labs funded research project Towards a Mobile Cloud (activity CLD 12206). * /*from w w w .ja v a 2 s. co m*/ * 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 { /** * Subtracts second array from the first * * @param first * @param second * @return first - second */ public static double[] subtract(double[] first, double[] second) throws Exception { if (first.length != second.length) { throw new Exception("Lengths of arrays are not equal"); } double[] returnValues = new double[first.length]; for (int i = 0; i < returnValues.length; i++) { returnValues[i] = first[i] - second[i]; } return returnValues; } /** * Subtract one matrix from another * * @param input1 * @param input2 * @return input1 - input2 * @throws Exception */ public static int[][] subtract(int[][] input1, int[][] input2) throws Exception { int rows = input1.length; int columns = input1[0].length; if (input2.length != rows) { throw new Exception("Row length of arrays are not equal"); } if (input2[0].length != columns) { throw new Exception("Column length of arrays are not equal"); } int[][] returnValues = new int[rows][columns]; for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { returnValues[r][c] = input1[r][c] - input2[r][c]; } } return returnValues; } }