Java Matrix Transpose matrixTrans_x_matrix(double[][] mat)

Here you can find the source of matrixTrans_x_matrix(double[][] mat)

Description

First transposes a matrix, then multiplies it with the original matrix.

License

Open Source License

Parameter

Parameter Description
mat The matrix (m x n).

Return

The resulting matrix of size n x n.

Declaration

public static double[][] matrixTrans_x_matrix(double[][] mat) 

Method Source Code

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

public class Main {
    /**//from   ww w. j av a  2  s. c  o m
     * First transposes a matrix, then multiplies it with the original matrix.
     * @param mat The matrix (m x n).
     * @return The resulting matrix of size n x n.
     */
    public static double[][] matrixTrans_x_matrix(double[][] mat) {
        final int m = mat.length;
        final int n = mat[0].length;

        // result is a symetrical square matrix
        double[][] res = new double[n][n];

        for (int r = 0; r < n; r++) {
            for (int c = r; c < n; c++) {
                for (int i = 0; i < m; i++) {
                    res[r][c] += mat[i][r] * mat[i][c];
                }
                // mirror result on diagonal axis
                res[c][r] = res[r][c];
            }
        }
        return res;
    }
}

Related

  1. matrixTrans_x_diagonalMatrix(double[][] mat, double[] diag)
  2. matrixTrans_x_diagonalMatrix_x_Matrix(double[][] mat, double[] diag)
  3. matrixTransform(Object[][] datas)
  4. matrixTranspose(Object[][] matrix)
  5. transpose(boolean[][] inputMatrix)
  6. transpose(boolean[][] matrix)