Java examples for java.lang:Math Matrix
First transposes a matrix, then multiplies it with another matrix that only contains elements on its diagonal.
//package com.java2s; public class Main { /**/*from w w w . j a v a 2 s . com*/ * 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; } }