MatrixInverse Method (Decimal) |
Namespace: Accord.Math
// Declare a matrix as double[,] matrix = { { 6.0, 1.0, 2.0 }, { 0.0, 8.0, 1.0 }, { 2.0, 4.0, 5.0 } }; // Compute the inverse using double[,] inv = matrix.Inverse(); // We can write the result with string strInv = inv.ToCSharp(); // The result should be: // new double[,] // { // { 0.193548387096774, 0.0161290322580645, -0.0806451612903226 }, // { 0.010752688172043, 0.139784946236559, -0.032258064516129 }, // { -0.0860215053763441, -0.118279569892473, 0.258064516129032 } // }; // We can confirm this is indeed the inverse by // checking whether "inv(matrix) * matrix" and // "matrix * inv(matrix)" equals I (identity): double[,] a = inv.Dot(matrix); double[,] b = matrix.Dot(inv); // Again we write the result: string strA = a.ToCSharp(); string strB = b.ToCSharp(); // The result should be: // new double[,] // { // { 1, 0, 0 }, // { 0, 1, 0 }, // { 0, 0, 1 } // };