Java Matrix Product matrix_vector_product(double[][] a, double[] v)

Here you can find the source of matrix_vector_product(double[][] a, double[] v)

Description

matrivectoproduct

License

Open Source License

Declaration

public static double[] matrix_vector_product(double[][] a, double[] v) 

Method Source Code

//package com.java2s;
/*/*from   ww  w.j  a v  a 2s  .  c  o m*/
 * AACalc - Asset Allocation Calculator
 * Copyright (C) 2009, 2011-2016 Gordon Irlam
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static double[] matrix_vector_product(double[][] a, double[] v) {
        double[] r = new double[a.length];
        for (int i = 0; i < a.length; i++)
            r[i] = dot_product(a[i], v);
        return r;
    }

    public static double dot_product(double[] v, double[] w) {
        assert (v.length == w.length);
        double r = 0.0;
        for (int i = 0; i < v.length; i++)
            r += v[i] * w[i];
        return r;
    }
}

Related

  1. matrixInnerProduct(int M, int N, double m1[][], double m2[][])
  2. matrixProduct(double[][] A, double[][] B)
  3. matrixProduct(double[][] m, double[][] n)
  4. matrixProduct(double[][] x, double[] y)