Click here to Skip to main content
11,706,639 members (42,065 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

la4j - Linear Algebra for Java

, 14 Nov 2011 CPOL 11.8K 251 7
Elegant and pure Java matrix library
 * Copyright 2011, Vladimir Kostyukov
 * This file is part of la4j project (
 * Licensed under the Apache License, Version 2.0 (the "License");
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.

package la4j.inversion;

import la4j.err.LinearSystemException;
import la4j.err.MatrixInversionException;
import la4j.factory.Factory;
import la4j.linear.GaussianSolver;
import la4j.linear.LinearSystem;
import la4j.linear.LinearSystemSolver;
import la4j.matrix.Matrix;
import la4j.vector.Vector;

public class GaussianInvertor implements MatrixInvertor {

	public Matrix inverse(Matrix matrix, Factory factory) throws MatrixInversionException {

		if (matrix.rows() != matrix.columns()) throw new MatrixInversionException();
		Matrix result = factory.createMatrix(matrix.rows(), matrix.columns());
		LinearSystemSolver solver = new GaussianSolver();
		try {
			for (int i = 0; i < matrix.rows(); i++) {
				Vector b = factory.createVector(matrix.rows());
				b.set(i, 1.0);
				LinearSystem system = new LinearSystem(matrix, b);
				Vector x = system.solve(solver, factory);
				result.setColumn(i, x);
		} catch (LinearSystemException ex) {
			throw new MatrixInversionException(ex.getMessage());
		return result;

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Vladimir Kostyukov
Software Developer Intel
Russian Federation Russian Federation
I've received a Master's Degree in Computer Science at the IT Faculty of Altai State Technical University, Russia.

Currently, I am Software Engineer at Intel Corporation.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150819.1 | Last Updated 14 Nov 2011
Article Copyright 2011 by Vladimir Kostyukov
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid