public void Inverse_Throws_IfDeterminantZero() { var values = new BigRational[2, 2] { { 2, 8 }, { 1, 4 } }; var matrix = new ImmutableMatrix2x2(values); Assert.Throws <InvalidOperationException>(() => matrix.Inverse()); }
public void Inverse_InvertsMatrix() { var values = new BigRational[2, 2] { { 2, 5 }, { 1, 4 } }; var matrix = new ImmutableMatrix2x2(values); var inverse = matrix.Inverse(); Assert.Equal(new BigRational(4, 3), inverse.UnderlyingValues[0, 0]); Assert.Equal(new BigRational(-5, 3), inverse.UnderlyingValues[0, 1]); Assert.Equal(new BigRational(-1, 3), inverse.UnderlyingValues[1, 0]); Assert.Equal(new BigRational(2, 3), inverse.UnderlyingValues[1, 1]); Assert.Equal(Constants.Matrices.I, matrix * inverse); }