Java Matrix Multiply multiplyVectorAndMatrix(double[] vector, double[][] matrix)

Here you can find the source of multiplyVectorAndMatrix(double[] vector, double[][] matrix)

Description

Multiplies a vector and a matrix.

License

Open Source License

Parameter

Parameter Description
vector Vector of integers.
matrix Matrix of integers.

Return

Vector result of multiplication of the vector and matrix.

Declaration

public static double[] multiplyVectorAndMatrix(double[] vector, double[][] matrix) 

Method Source Code

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

public class Main {
    /**/*from   ww w  . j a  v  a  2 s .  c o  m*/
     * Multiplies a vector and a matrix. The multiplication order is: vector *
     * matrix. The result of multiplication is a vector.
     *
     * @param vector   Vector of integers.
     * @param matrix   Matrix of integers.
     * @return   Vector result of multiplication of the vector and matrix.
     */
    public static double[] multiplyVectorAndMatrix(double[] vector, double[][] matrix) {

        double[] res = new double[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < vector.length; j++) {
                res[i] += matrix[i][j] * vector[j];
            }
        }

        return res;
    }

    /**
     * Multiplies a vector and a matrix. The multiplication order is: vector *
     * matrix. The result of multiplication is a vector.
     *
     * @param vector   Vector of integers.
     * @param matrix   Matrix of integers.
     * @return   Vector result of multiplication of the vector and matrix.
     */
    public static double[] multiplyVectorAndMatrix(int[] vector, int[][] matrix) {

        double[] res = new double[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < vector.length; j++) {
                res[i] += (double) matrix[i][j] * (double) vector[j];
            }
        }

        return res;
    }
}

Related

  1. multiplyMatrixes(double[][] m1, double[][] m2)
  2. multiplyQuad(final double[][] A, final double[][] B, final double[][] dest, int n)
  3. multiplyScalars(float[][] x, float[][] y)
  4. multiplyScalars_optimizedByKnowingBothAreRectangle(float[][] x, float[][] y)
  5. multiplySparse2dense(int[][][] as, int A, int[][][] bs, int B, int[][] c)
  6. multiplyVectorByMatrix(double[] v, double[][] m)