Questions about operation A\B
Mostrar comentarios más antiguos
In MATLAB, A\B computes a least-squares solution to the system of equations A*x= B.. I'd like to know the specific method MATLAB employs—QR decomposition, SVD decomposition, or another approach—to achieve this.
A = [1 2 0; 0 4 3];
b = [8; 18];
x = A\b
I attempted a similar implementation in C++ using QR decomposition and validated it against 30 data sets. Surprisingly, 29 sets matched MATLAB perfectly, but one exhibited a significant difference. I'm puzzled because if the implementation were flawed, I'd expect inconsistencies across all data.
Respuesta aceptada
Más respuestas (1)
John D'Errico
el 6 de En. de 2024
Editada: John D'Errico
el 6 de En. de 2024
1 voto
The only time when there would/should ever be any significant difference is if the matrix is singular. And in that case, there would be infinitely many possible solutions, all of which are equally good, or bad.
In the singular case, different methods will result in different characteristic solutions, some of which may be more preferred than others, but the choice of your preference is often problem dependent.
As well, different methods will have different speeds. For example, any solution which depends on the SVD will often be considerably slower on large problems. Other solutions will generate zero coefficients on singular problems, whereas the pseudo-inverse based on the SVD will not tend to do so. (However, there are no circumstances where backslash uses the SVD.)
Again, problem dependent, and your needs and goals may differ on different problems.
1 comentario
lucky
el 6 de En. de 2024
Categorías
Más información sobre Linear Algebra en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!