Java Matrix Multiply multiplyMatrix(int[][] a, int[] b, int mod)

Here you can find the source of multiplyMatrix(int[][] a, int[] b, int mod)

Description

Multiplies the input matrix a with the input vector b % mod

License

Open Source License

Parameter

Parameter Description
a The matrix to multiply with. a.length = b.length
b A vector to multiply with the matrix where b.length = a.length
mod The modulus used. See HillCipher.ALPHA_CHARS, HillCipher.ALL_CHARS for options

Return

The vector product of the multiplication (a, b) % mod

Declaration

public static int[] multiplyMatrix(int[][] a, int[] b, int mod) 

Method Source Code

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

public class Main {
    /**// ww  w .  ja va 2  s.  c o m
     * Multiplies the input matrix a with the input vector b % mod
     * @param a The matrix to multiply with. a.length = b.length
     * @param b A vector to multiply with the matrix where b.length = a.length
     * @param mod The modulus used. See HillCipher.ALPHA_CHARS, HillCipher.ALL_CHARS for options
     * @return The vector product of the multiplication (a, b) % mod
     */
    public static int[] multiplyMatrix(int[][] a, int[] b, int mod) {
        int m = b.length;
        int[] resultMatrix = new int[m];

        for (int i = 0; i < m; i++) {
            int total = 0;

            for (int j = 0; j < m; j++) {
                int aValue = a[i][j];
                int bValue = b[j];
                total += aValue * bValue;
            }

            resultMatrix[i] = total % mod;
        }

        return resultMatrix;
    }
}

Related

  1. multiply(String[] tempResult, int nextIndex, String[][] pys)
  2. multiplyAffine(final double[][] A, final double[][] B, final double[][] dest, int n)
  3. multiplyMatrices(double[][] a, double[][] b)
  4. multiplyMatrices(float[][] left, float[][] right)
  5. multiplyMatrices(int[][] mat1, int[][] mat2)
  6. multiplyMatrixByMatrix(double[][] a, double[][] b)
  7. multiplyMatrixes(double[][] m1, double[][] m2)
  8. multiplyQuad(final double[][] A, final double[][] B, final double[][] dest, int n)
  9. multiplyScalars(float[][] x, float[][] y)