/// <summary> /// LU decomposition and LU inverse example /// </summary> public static void LUExample() { double[,] m = {{2, 3, 3, 5}, {6, 6, 8, 9}, {10, 11, 12, 13}, {14, 15, 17, 17}}; PZMath_matrix matrix = new PZMath_matrix(m); matrix.ScreenWriteLine(); // LU decomposition // correct answer: // L = // 1.0000 0 0 0 // 0.1429 1.0000 0 0 // 0.4286 -0.5000 1.0000 0 // 0.7143 0.3333 -0.3333 1.0000 // U = // 14.0000 15.0000 17.0000 17.0000 // 0 0.8571 0.5714 2.5714 // 0 0 1.0000 3.0000 // 0 0 0 1.0000 // P = // 0 0 0 1 // 1 0 0 0 // 0 1 0 0 // 0 0 1 0 PZMath_permutation p = new PZMath_permutation(matrix.RowCount); PZMath_matrix LU = matrix.LUDecomp(p); LU.ScreenWriteLine(); // LU Invert // correct answer: // inv(m) = // -2.0833 0.6667 3.5000 -2.4167 // 1.0000 -1.0000 -1.0000 1.0000 // 1.0000 0 -3.0000 2.0000 // -0.1667 0.3333 1.0000 -0.8333 PZMath_matrix inverse = matrix.LUInvert(); inverse.ScreenWriteLine(); }