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

double[][]invert(double a[][])
invert
int n = a.length;
double x[][] = new double[n][n];
double b[][] = new double[n][n];
int index[] = new int[n];
for (int i = 0; i < n; ++i) {
    b[i][i] = 1;
gaussian(a, index);
...
int[][]invert(final int[][] input)
invert
int L1 = input.length;
int L2 = input[0].length;
int[][] rtr = new int[L2][L1];
for (int i = 0; i < L1; i++)
    for (int j = 0; j < L2; j++)
        rtr[j][i] = input[i][j];
return rtr;
voidinvert(float[] mat)
invert
float dx = -mat[3];
float dy = -mat[7];
float dz = -mat[11];
invert3x3(mat);
mat[3] = mat[0] * dx + mat[1] * dy + mat[2] * dz;
mat[7] = mat[4] * dx + mat[5] * dy + mat[6] * dz;
mat[11] = mat[8] * dx + mat[9] * dy + mat[10] * dz;
voidinvert2x2(final double[][] src, final double[][] dest)
Copy the inverse of the 2-by-2 matrix src intro 2-by-2 matrix dest
assert hasShape(src, 2, 2);
assert hasShape(dest, 2, 2);
assert src != dest;
final double tmp = src[0][0] * src[1][1] - src[0][1] * src[1][0];
if (tmp == 0.) {
    throw new Exception();
dest[0][0] = src[1][1] / tmp;
...
voidinvert3x3(float[] mat)
invertx
double sub00 = mat[5] * mat[10] - mat[6] * mat[9];
double sub01 = mat[4] * mat[10] - mat[6] * mat[8];
double sub02 = mat[4] * mat[9] - mat[5] * mat[8];
double sub10 = mat[1] * mat[10] - mat[2] * mat[9];
double sub11 = mat[0] * mat[10] - mat[2] * mat[8];
double sub12 = mat[0] * mat[9] - mat[1] * mat[8];
double sub20 = mat[1] * mat[6] - mat[2] * mat[5];
double sub21 = mat[0] * mat[6] - mat[2] * mat[4];
...
booleaninvert44Matrix(final double[] m, final double[] invOut)
invert Matrix
double[] inv = new double[16];
int i;
inv[0] = m[5] * m[10] * m[15] - m[5] * m[11] * m[14] - m[9] * m[6] * m[15] + m[9] * m[7] * m[14]
        + m[13] * m[6] * m[11] - m[13] * m[7] * m[10];
inv[4] = -m[4] * m[10] * m[15] + m[4] * m[11] * m[14] + m[8] * m[6] * m[15] - m[8] * m[7] * m[14]
        - m[12] * m[6] * m[11] + m[12] * m[7] * m[10];
inv[8] = m[4] * m[9] * m[15] - m[4] * m[11] * m[13] - m[8] * m[5] * m[15] + m[8] * m[7] * m[13]
        + m[12] * m[5] * m[11] - m[12] * m[7] * m[9];
...
double[][]invertDataSet(double[][] dataSet)
invert Data Set
double[][] kdkdinv = new double[dataSet.length][dataSet[0].length];
for (int i = 0; i < dataSet.length; i++) {
    for (int j = 0; j < dataSet.length; j++) {
        if (!Double.isNaN(dataSet[i][j]))
            kdkdinv[i][j] = 1 - dataSet[i][j];
        else
            kdkdinv[i][j] = Double.NaN;
return kdkdinv;
int[][]invertMatrix(int[][] matrix)
invert Matrix
int[][] newMatrix = new int[matrix[0].length][matrix.length];
for (int x = 0; x < newMatrix[0].length; x++) {
    for (int y = 0; y < newMatrix.length; y++) {
        newMatrix[x][y] = matrix[y][x];
return newMatrix;
booleaninvertMatrix3x3(float[] result, float[] m)
Invert a 3x3 matrix.
float A = m[5] * m[10] - m[6] * m[9];
float B = m[6] * m[8] - m[4] * m[10];
float C = m[4] * m[9] - m[5] * m[8];
float det = m[0] * A + m[1] * B + m[2] * C;
if (det == 0.f) {
    return false;
float invertedDet = 1.f / det;
...
double[][]invertMatrix4x4(double[][] A)
Inverts a 4 x 4 matrix using Gaussian Elimination.
double s1, s2, s3, s4;
double negX, div;
double r1fab, r2fab, r3fab, r4fab;
double[] A_row0 = A[0];
double[] A_row1 = A[1];
double[] A_row2 = A[2];
double[] A_row3 = A[3];
double[][] res = new double[4][4];
...