Java Matrix matrix_x_vectorMatrix(double[][] mat, double[][] vector, int vectorCol)

Here you can find the source of matrix_x_vectorMatrix(double[][] mat, double[][] vector, int vectorCol)

Description

Multiplies a matrix with another matrix that only has one column.

License

Open Source License

Parameter

Parameter Description
mat The matrix (m x n).
vector The matrix that only contains one column. It is a two-dimensional array, the parameter vectorCol determines which column holds the vector.
vectorCol The column that holds the vector data.

Return

The resulting matrix of size m x 1.

Declaration

public static double[] matrix_x_vectorMatrix(double[][] mat, double[][] vector, int vectorCol) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from   w w w . j a v  a 2s.com
     * Multiplies a matrix with another matrix that only  has one column.
     * @param mat The matrix (m x n).
     * @param vector The matrix that only contains one column. It is a
     * two-dimensional array, the parameter vectorCol determines which column
     * holds the vector.
     * @param vectorCol The column that holds the vector data.
     * @return The resulting matrix of size m x 1.
     */
    public static double[] matrix_x_vectorMatrix(double[][] mat, double[][] vector, int vectorCol) {

        final int m = mat.length;
        final int n = mat[0].length;

        double[] res = new double[m];

        for (int row = 0; row < m; row++) {
            for (int col = 0; col < n; col++) {
                res[col] += mat[row][col] * vector[col][vectorCol];
            }
        }

        return res;
    }
}

Related

  1. matrix_x_matrix(double[][] A, double[][] B)
  2. matrixAbsDiff(double m1[][], double m2[][])
  3. matrixATrans_x_matrixB(double[][] matA, double[][] matB)
  4. matrixConcatLR(double[][] LMatrix, double[][] RMatrix)
  5. matrixConcatUL(double[][] UMatrix, double[][] LMatrix)