Click or drag to resize
Accord.NET (logo)

MatrixInverse Method (Single)

Computes the inverse of a matrix.

Namespace:  Accord.Math
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.8.0
Syntax
public static float[][] Inverse(
	this float[][] matrix
)
Request Example View Source

Parameters

matrix
Type: SystemSingle

Return Value

Type: Single

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type . When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Examples
// 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 }
// };
See Also