/** * */ package util; /** * Performs Matrix Operations. * @author John H. Krantz, Ph.D. * */ public class Matrix { /** * Does a standard matrix muliplication operation. * Assumes that at the number of columns of m1 = number * of rows of m2 * @param double [][] m1 * @param double [][] m2 * @return */ public double [][] mMult(double [][] m1, double [][] m2){ double [][] temp = null; // test that matrices fit requirements if (m1[0].length == m2.length){ temp = new double [m1.length][m2[0].length]; for (int i = 0; i < temp.length; i ++){ for (int j = 0; j < temp[0].length; j ++){ temp[i][j] = 0; for (int r = 0; r < m1[0].length; r ++){ temp[i][j] += m1[i][r]*m2[r][j]; }// end for r }// end for j } // end for i } // end doing matrix mult return temp; } /** * Does a standard matrix muliplication operation. * Assumes that at the number of columns of m1 = number * of elements of m2 and m2 is a one dimensional array. * @param double [][] m1 * @param double [] m2 * @return */ public double [] mMult(double [][] m1, double [] m2){ // convert one dimensional array to a 2d array // and use over version of this method double [][] temp = new double [m2.length][1]; for (int i = 0; i < m2.length; i ++){ temp[i][0] = m2[i]; } // do the matrix multiplication double [][] tt = mMult(m1,temp); // convert output to 1d array double t [] = new double[m2.length]; for (int i = 0; i < m2.length; i ++){ t[i] = tt[i][0]; } return t; } }