Java tutorial
/******************************************************************************* * Copyright (c) 2013 American Institutes for Research * * This file is part of AIROSE. * * AIROSE is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * AIROSE is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with AIROSE. If not, see <http://www.gnu.org/licenses/>. ******************************************************************************/ package org.opentestsystem.airose.linear; import org.apache.commons.math3.linear.DiagonalMatrix; import org.apache.commons.math3.linear.RealMatrix; import java.util.Vector; public class Matrix { protected RealMatrix _matrix = null; protected Matrix(RealMatrix m) { this._matrix = m; } public void set(int row, int column, double value) { _matrix.setEntry(row, column, value); } public double get(int row, int column) { return _matrix.getEntry(row, column); } public int rows() { return _matrix.getRowDimension(); } public int columns() { return _matrix.getColumnDimension(); } public Matrix multiply(Matrix m2) { return new Matrix(_matrix.multiply(m2._matrix)); } public Matrix transpose(Matrix matrix) { Matrix transeposedMat = new Matrix(_matrix.transpose()); return transeposedMat; } public MatrixTypeEnum getMatrixType() { if (_matrix instanceof DiagonalMatrix) return MatrixTypeEnum.DIAGONAL; else return MatrixTypeEnum.REAL2D; } @SuppressWarnings("rawtypes") public Vector getRowVector(int row) { Vector<Double> vector = new Vector<Double>(); vector.setSize(columns()); for (int i = 0; i < columns(); i++) { vector.set(i, _matrix.getEntry(row, i)); } return vector; } }