*** REQUEST FOR FURTHER FORUM HELP AT THE END OF THIS POST ***
In matrix.h:
Line 199 AND line 212 should have
and not
Line 209 should have
and not
(you have already set the diagonal element)
Line 201 should be
sum = sum + (lower.getValue(i,j) * upper.getValue(j,k));
Line 214 should be
sum = sum + (lower.getValue(k,j) * upper.getValue(j,i));
Line 192 requires references if you want to return some values
void factorize(mat &upper, mat &lower)
In main.cpp the multiplication order should be LU, and you have UL.
Line 34 in main.cpp should be
A = B.matMul(C,B);
OK - that solves your immediate problem (at least, it did on my PC).
However, there are a huge number of problems with your code.
First, on the LU algorithm. It is hugely confusing to have separate buildU and buildL routines to set first row and column and the unit diagonal elements. Just put the appropriate lines of code in the factorize() method.
Second, the matrix multiply. Why do you need all these cases (which won't actually work anyway for a non-square matrix)? You only need a single case: there is nothing wrong with having a loop that only actually runs once.
Then the C++ ...
- all this code in the header file ... ?
- you don't need
all the time: if it's a member function then it has access to all the member data anyway.
- you are using new ... without delete; this is going to cause significant memory leaks; your destructor needs to clear these pointers.
*** FURTHER FORUM HELP REQUIRED ***
I'm going to call for help from the more C++-knowledgeable on this forum as to whether you need to overload the = operator for your (to-be-corrected) line
A = B.matMul(C,B);
since both A and the return matrix from the function will have dynamically-allocated memory.