Java Matrix Invert invertUpperTriangular(double[][] r)

Here you can find the source of invertUpperTriangular(double[][] r)

Description

Uses backward substitution to invert an upper triangular matrix.

License

Open Source License

Declaration

public static double[][] invertUpperTriangular(double[][] r) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from ww  w.j a  v a2s  .  co m
     * Uses backward substitution to invert an upper triangular matrix.
     */
    public static double[][] invertUpperTriangular(double[][] r) {
        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;
    }
}

Related

  1. invertMatrix3x3(float[] result, float[] m)
  2. invertMatrix4x4(double[][] A)
  3. invertRegions(int[][] image)
  4. invertSymmetric2x2(final double[][] m, final double[][] inverse)
  5. invertSymmetric3x3(final double[][] m, final double[][] inverse)