Dot Product between list of double value - Java java.lang

Java examples for java.lang:double Array

Description

Dot Product between list of double value

Demo Code

/*//from w  w w  .ja  v  a2 s  . c  om
 * VectorHelpers.java
 * Copyright (C) 2014 Amin Bandali <me@aminb.org>
 *
 * MATHTools 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.
 *
 * MATHTools 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 this program. If not, see <http://www.gnu.org/licenses/>.
 */
//package com.java2s;
import java.util.List;

public class Main {
    public static double calcDotProduct(List<Double> in1, List<Double> in2) {
        Double dotProduct = 0d;

        for (int i = 0; i < in1.size(); i++) {
            dotProduct += in1.get(i) * in2.get(i);
        }

        return dotProduct;
    }
}

Related Tutorials