Here you can find the source of subtract(List
Parameter | Description |
---|---|
a | Vector to subtract from |
b | Vector to subtract |
public static List<Float> subtract(List<Float> a, List<Float> b)
//package com.java2s; /******************************************************************************* * This file is part of Tmetrics./*from ww w .ja v a 2s .co m*/ * * Tmetrics is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Tmetrics 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Tmetrics. If not, see <http://www.gnu.org/licenses/>. *******************************************************************************/ import java.util.ArrayList; import java.util.List; public class Main { /** * Vector subtraction * * Modifies the first parameter but also returns it for convenience. Vectors * must be of same length. * * @param a * Vector to subtract from * @param b * Vector to subtract * @return Result */ public static List<Float> subtract(List<Float> a, List<Float> b) { if (a.size() != b.size()) { throw new IllegalArgumentException( "Length of vector a (" + a.size() + ") does not equal length of vector b (" + b.size() + ")"); } List<Float> c = new ArrayList<Float>(); for (int i = 0; i < a.size(); i++) { c.add(a.get(i) - b.get(i)); } return c; } }