Java Utililty Methods Matrix Invert

List of utility methods to do Matrix Invert

Description

The list of methods to do Matrix Invert are organized into topic(s).

Method

int[][]invertRegions(int[][] image)
invert Regions
final int height = image.length;
final int width = height > 0 ? image[0].length : 0;
for (int y = 0; y < height; y++)
    for (int x = 0; x < width; x++)
        image[y][x] = image[y][x] == 0 ? 1 : 0;
return image;
voidinvertSymmetric2x2(final double[][] m, final double[][] inverse)
Inverts a (invertible) symmetric 2x2 matrix.
final double Dinv = 1.0 / (m[0][0] * m[1][1] - m[1][0] * m[1][0]);
inverse[0][0] = m[1][1] * Dinv;
inverse[1][0] = inverse[0][1] = -m[1][0] * Dinv;
inverse[1][1] = m[0][0] * Dinv;
voidinvertSymmetric3x3(final double[][] m, final double[][] inverse)
Inverts a (invertible) symmetric 3x3 matrix.
final double a00 = m[2][2] * m[1][1] - m[1][2] * m[1][2];
final double a01 = m[0][2] * m[1][2] - m[2][2] * m[0][1];
final double a02 = m[0][1] * m[1][2] - m[0][2] * m[1][1];
final double a11 = m[2][2] * m[0][0] - m[0][2] * m[0][2];
final double a12 = m[0][1] * m[0][2] - m[0][0] * m[1][2];
final double a22 = m[0][0] * m[1][1] - m[0][1] * m[0][1];
final double Dinv = 1.0 / ((m[0][0] * a00) + (m[1][0] * a01) + (m[0][2] * a02));
inverse[0][0] = a00 * Dinv;
...
double[][]invertUpperTriangular(double[][] r)
Uses backward substitution to invert an upper triangular matrix.
int dim = Math.min(r.length, r[0].length);
double[][] inv = new double[dim][dim];
for (int i = dim - 1; i >= 0; i--) {
    inv[i][i] = 1.0 / r[i][i];
    for (int j = i + 1; j < dim; j++) {
        for (int k = i + 1; k < dim; k++) {
            inv[i][j] -= r[i][k] * inv[k][j];
        inv[i][j] *= inv[i][i];
return inv;