MATLAB: Solve A*X=B matricial equation

matricial equationsingular matrix

Hello everyone,
I have some troubles obtaining the X matrix (unknown) from the next matricial equation A*X=B
I know A and B and if they were square matrix this problem would be easy to solve: X=inv(A)*B
Actually, A and B are not square matrix, they are (4410 x 3) matrix and in order to solve this equation I use the transpose matrix of A to make it square and use its inverse as follows:
X=inv(A'*A)*A'*B I obtain X as a (3 x 3) square matrix
My problem is that if I multiply the A matrix and the X matrix I just obtain, (A*X) the result is not exactly B, it is very diferent. I think the equation and its calculation is correct and I suspect the problem is in the amount of rows because if I repeat the calculation with only 6 rows (instead 4410), there is no problem and the values go worst according as the number of rows increase.
Then I decided to split A and B matrix in smaller submatrix in order to repeat the calculation and join again the results, but the most of the "submatrix" were closely to singular matrix and I obtain a matrix with some NaN values.
I would like to know if my problem is something usual or if I am wrong.
Thank you very much
Best regards

Best Answer

You should be solving for X using mldivide,
X=A\B
A result exactly equal to B isn't to be expected unless an exact simultaneous solution to A*X=B exists. Otherwise, you just get a least squares solution.
Related Question