Java Matrix Multiply multiply(double[][] a, double[][] x)

Here you can find the source of multiply(double[][] a, double[][] x)

Description

multiply

License

Open Source License

Declaration

public static double[][] multiply(double[][] a, double[][] x) 

Method Source Code

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

public class Main {
    public static double[][] multiply(double[][] a, double[][] x) {
        double[][] y = new double[a.length][x[0].length];
        double[][] x_t = transpose(x);
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < x_t.length; j++) {
                y[i][j] = dotProduct(a[i], x_t[j]);
            }// ww  w  . j a  va 2  s .co  m
        }
        return y;
    }

    public static double[][] transpose(double[][] x) {
        double[][] t = new double[x[0].length][x.length];
        for (int i = 0; i < x.length; i++) {
            for (int j = 0; j < x[0].length; j++) {
                t[j][i] = x[i][j];
            }
        }
        return t;
    }

    public static double dotProduct(double[] xs1, double[] xs2) {
        double product = 0;
        for (int i = 0; i < xs1.length; i++) {
            product += xs1[i] * xs2[i];
        }
        return product;
    }
}

Related

  1. matrixMultiplyWithThreadOffset(double[] A, double[] Adiag, double[] B, int aHeight, int bWidth, int comm, int bz, int threadRowOffset, int rowOffset, double[] C)
  2. matrixScalarMultiplication(double[][] w, double v)
  3. multiply(boolean[][] m1, boolean[][] m2)
  4. multiply(boolean[][] matrix, boolean[] vector)
  5. multiply(double[][] a, double[][] b)
  6. multiply(double[][] dest, double[][] a, double[][] b)
  7. multiply(double[][] m, double[] x)
  8. multiply(double[][] m1, double[][] m2)
  9. multiply(double[][] p, double[][] q)