/** * Gets a row of the matrix and returns it as double array. * * @param index the row's index * @return an array of doubles */ public double[] getRow(int index) { double[] newRow = new double[this.numColumns()]; for (int i = 0; i < newRow.length; i++) { newRow[i] = getElement(index, i); } return newRow; }
/** * Gets a column of the matrix and returns it as a double array. * * @param index the column's index * @return an array of doubles */ public double[] getColumn(int index) { double[] newColumn = new double[this.numRows()]; for (int i = 0; i < newColumn.length; i++) { newColumn[i] = getElement(i, index); } return newColumn; }
/** * Gets a row of the matrix and returns it as double array. * * @param index the row's index * @return an array of doubles */ public double[] getRow(int index) { double[] newRow = new double[this.numColumns()]; for (int i = 0; i < newRow.length; i++) { newRow[i] = getElement(index, i); } return newRow; }
/** * Gets a column of the matrix and returns it as a double array. * * @param index the column's index * @return an array of doubles */ public double[] getColumn(int index) { double[] newColumn = new double[this.numRows()]; for (int i = 0; i < newColumn.length; i++) { newColumn[i] = getElement(i, index); } return newColumn; }
/** * Returns the U part of the matrix. This does only make sense after LU * decomposition. * * @return matrix with the U part of a matrix; * @see #LUDecomposition() */ public Matrix getU() throws Exception { int nr = numRows(); // num of rows int nc = numColumns(); // num of columns double[][] ud = new double[nr][nc]; for (int i = 0; i < nr; i++) { for (int j = i; j < nc; j++) { ud[i][j] = getElement(i, j); } } Matrix u = new Matrix(ud); return u; }
/** * Returns the U part of the matrix. This does only make sense after LU * decomposition. * * @return matrix with the U part of a matrix; * @see #LUDecomposition() */ public Matrix getU() throws Exception { int nr = numRows(); // num of rows int nc = numColumns(); // num of columns double[][] ud = new double[nr][nc]; for (int i = 0; i < nr; i++) { for (int j = i; j < nc; j++) { ud[i][j] = getElement(i, j); } } Matrix u = new Matrix(ud); return u; }
/** * Returns the L part of the matrix. This does only make sense after LU * decomposition. * * @return matrix with the L part of the matrix; * @see #LUDecomposition() */ public Matrix getL() throws Exception { int nr = numRows(); // num of rows int nc = numColumns(); // num of columns double[][] ld = new double[nr][nc]; for (int i = 0; i < nr; i++) { for (int j = 0; (j < i) && (j < nc); j++) { ld[i][j] = getElement(i, j); } if (i < nc) { ld[i][i] = 1; } } Matrix l = new Matrix(ld); return l; }
/** * Returns the L part of the matrix. This does only make sense after LU * decomposition. * * @return matrix with the L part of the matrix; * @see #LUDecomposition() */ public Matrix getL() throws Exception { int nr = numRows(); // num of rows int nc = numColumns(); // num of columns double[][] ld = new double[nr][nc]; for (int i = 0; i < nr; i++) { for (int j = 0; (j < i) && (j < nc); j++) { ld[i][j] = getElement(i, j); } if (i < nc) { ld[i][i] = 1; } } Matrix l = new Matrix(ld); return l; }
System.out.println("a:\n " + a); System.out.println("b:\n " + b); System.out.println("a (0, 0): " + a.getElement(0, 0)); System.out.println("a transposed:\n " + a.transpose()); System.out.println("a * b:\n " + a.multiply(b));
System.out.println("a:\n " + a); System.out.println("b:\n " + b); System.out.println("a (0, 0): " + a.getElement(0, 0)); System.out.println("a transposed:\n " + a.transpose()); System.out.println("a * b:\n " + a.multiply(b));