Here you can find the source of matrixTrans_x_diagonalMatrix(double[][] mat, double[] diag)
Parameter | Description |
---|---|
mat | The matrix (m x n). |
diag | The matrix that only contains elements on its diagonal, as a one-dimensional vector of size n x 1 that represents the matrix of size n x n. |
public static double[][] matrixTrans_x_diagonalMatrix(double[][] mat, double[] diag)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . j av a2 s .c o m * First transposes a matrix, then multiplies it with another matrix that * only contains elements on its diagonal (0 elswhere). * @param mat The matrix (m x n). * @param diag The matrix that only contains elements on its diagonal, as a one-dimensional * vector of size n x 1 that represents the matrix of size n x n. * @return The resulting matrix of size m x n. */ public static double[][] matrixTrans_x_diagonalMatrix(double[][] mat, double[] diag) { final int m = mat.length; final int n = mat[0].length; double[][] res = new double[n][m]; for (int row = 0; row < n; row++) { for (int col = 0; col < m; col++) { res[row][col] = mat[col][row] * diag[col]; } } return res; } }