Hello
I have a problem with the function Invert in the NotSoBasicLinearAlgebra.h header file.
This is its definition:
template <int dim, class MemT>
bool Invert(const Matrix<dim, dim, MemT> &A, Matrix<dim, dim, MemT> &out)
The function has to return a boolean value:
"true" if the matrix is not singular (i.e. it is reversible) or "false" if it is singular (not reversible).
My problem is that the function always return "true" although it is singular.
Here is a example code:
loop
{
Matrix<4, 4, Array<4, 4, int>> Matr; //matrix of 4x4
Matrix<4, 4, Array<4, 4, int>> InvMatr; //invert matrix of 4x4
int arr2[4][4] = { {1,0,0,0},{0,1,0,0},{1,1,0,0},{0,0,0,1} }; //example of singular matrix
Matr = arr2; //init. Matr
bool b = Invert(Matr, InvMatr); //call to invert func. must return false
Serial.println("Matr:");
Check<Matr.Rows, Matr.Cols>(Matr); //display Matr
Serial.print("b = ");
Serial.println(b); //print Invert() return
Serial.println("InvMatr:");
Check<InvMatr.Rows, InvMatr.Cols>(InvMatr); //display inverted matrix
}
With Check function defined to print the matrix
template <int R, int C, class T = Array<R, C, float>>
void Check(Matrix<R, C, Array<R, C, T>> m)
{
for (int i = 0; i < R; i++)
{
for (int j = 0; j < C; j++)
{
Serial.print(m(i, j));
Serial.print(" ");
}
Serial.println("");
}
Serial.println("");
}
The result is:
Matr:
1 0 0 0
0 1 0 0
1 1 0 0
0 0 0 1
b = 1
InvMatr:
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0