The short answer is:
When the system
A*x = b
is overdetermined, both algorithms provide the same answer. When the system is underdetermined, PINV will return the solutionx
, that has the minimum norm (minNORM(x)
). MLDIVIDE will pick the solution with least number of non-zero elements.
As for how mldivide
works, MathWorks also posted a description of how the function operates.
However, you might also want to have a look at this answer for the first part of the discussion about mldivide
vs. other methods when the matrix A
is square.
Depending on the shape and composition of the matrix you would use either Cholesky decomposition for symmetric positive definite, LU decomposition for other square matrix or QR otherwise. Then you can can hold onto the factorization and use linsolve
to essentially just do back-substitution for you.
As to whether mldivide
is preferable to pinv
when A
is either not square (overspecified) or is square but singular, the two options will give you two of the infinitely many solutions. According to those docs, both solutions will give you exact solutions:
Both of these are exact solutions in the sense that
norm(A*x-b)
andnorm(A*y-b)
are on the order of roundoff error.