public void SolveTest1()
{
double[,] a =
{
{ 1, 2, 3 },
{ 4, 5, 6 },
};
double[,] b =
{
{ 7, 8, 9 },
{ 10, 11, 12 },
};
// Test with more rows than columns
{
double[,] matrix = a.Transpose();
double[,] rightSide = b.Transpose();
Assert.IsTrue(matrix.GetLength(0) > matrix.GetLength(1));
double[,] expected =
{
{ -1, -2 },
{ 2, 3 }
};
double[,] actual = Matrix.Solve(matrix, rightSide);
Assert.IsTrue(expected.IsEqual(actual, 1e-10));
}
// test with more columns than rows
{
double[,] matrix = a;
double[,] rightSide = b;
Assert.IsTrue(matrix.GetLength(0) < matrix.GetLength(1));
double[,] expected =
{
{ -13/6.0, -8/3.0, -19/6.0 },
{ 2/6.0, 2/6.0, 2/6.0 },
{ 17/6.0, 20/6.0, 23/6.0 }
};
double[,] actual = Matrix.Solve(matrix, rightSide);
Assert.IsTrue(expected.IsEqual(actual, 1e-10));
}
}