org.ejml.alg.dense.linsol.InvertUsingSolve Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ejml Show documentation
Show all versions of ejml Show documentation
A fast and easy to use dense matrix linear algebra library written in Java.
/*
* Copyright (c) 2009-2012, Peter Abeles. All Rights Reserved.
*
* This file is part of Efficient Java Matrix Library (EJML).
*
* EJML is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* EJML 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with EJML. If not, see .
*/
package org.ejml.alg.dense.linsol;
import org.ejml.data.DenseMatrix64F;
import org.ejml.data.RowD1Matrix64F;
import org.ejml.factory.LinearSolver;
import org.ejml.ops.CommonOps;
/**
* A matrix can be easily inverted by solving a system with an identify matrix. The only
* disadvantage of this approach is that additional computations are required compared to
* a specialized solution.
*
* @author Peter Abeles
*/
public class InvertUsingSolve {
public static void invert( LinearSolver solver , RowD1Matrix64F A , DenseMatrix64F A_inv , DenseMatrix64F storage) {
if( A.numRows != A_inv.numRows || A.numCols != A_inv.numCols) {
throw new IllegalArgumentException("A and A_inv must have the same dimensions");
}
CommonOps.setIdentity(storage);
solver.solve(storage,A_inv);
}
public static void invert( LinearSolver solver , RowD1Matrix64F A , DenseMatrix64F A_inv ) {
if( A.numRows != A_inv.numRows || A.numCols != A_inv.numCols) {
throw new IllegalArgumentException("A and A_inv must have the same dimensions");
}
CommonOps.setIdentity(A_inv);
solver.solve(A_inv,A_inv);
}
}