how can I solve a over deterministic system with least square method?
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
mostafa moazzemi
el 3 de Ag. de 2014
Comentada: Ahmet Cecen
el 4 de Ag. de 2014
I have a over deterministic equation like A*B=C that A&C are known and B is unknown and C is m*1 & A is m*n and B is n*1. In other hand m>n. How can I solve this system for calculating B matrix.
0 comentarios
Respuesta aceptada
John D'Errico
el 3 de Ag. de 2014
Editada: John D'Errico
el 3 de Ag. de 2014
Use backslash.
B = A\C;
Nothing more than that. It is...
- One line.
- Fast.
- Efficient.
- Accurate.
- No fancy codes needed.
- No extra toolboxes.
- Nothing to download.
- Works for under and overdetermined systems, also sparse problems.
What more could you ask for?
Some might prefer
B = pinv(A)*C;
because of the way it handles rank deficient and underdetermined systems, but it is slower than backslash, especially on large problems.
What you want very much to avoid are the codes that use the normal equations, and ESPECIALLY INV, thus
B = inv(A'*A)*A'*C;
That is just bad linear algebra, bad from the standpoint of numerical analysis. Use the backslash or pinv solutions instead.
3 comentarios
John D'Errico
el 3 de Ag. de 2014
Editada: John D'Errico
el 3 de Ag. de 2014
No. I absolutely disagree. "Every regression out there" will not definitely use that one liner. In fact, I am continuously amazed at the number of tools I see that do use the normal equation form instead. I also see a fair number of people that used fminsearch, or some other general nonlinear optimizer to solve for a linear least squares problem. So no, it is not at all true that EVERY regression does the above.
Even the code you wrote yourself does not use \ or pinv explicitly as I wrote it, but a variation thereof. I did not look carefully to see if your code uses a pivoted QR, which can be something of real importance if it does not do so.
As far as the other statistics generated, the person never asked for those statistics, so a code that does return them may be overkill.
Finslly, your solutions as posed require the person to either buy the stats toolbox, or to download and install your tools (trusting that you did a good job of writing them. I assume you did. They looked reasonable to me at a glance.)
Ahmet Cecen
el 4 de Ag. de 2014
I stand corrected with the one liners comment. I did my own survey and apparently many use other methods. +1 more bump.
Más respuestas (1)
Ahmet Cecen
el 3 de Ag. de 2014
Check the function regress if you have the statistics toolbox.
If you don't have the toolbox, you can use a variety of functions available in the File Exchange, including one from yours truly called MultiPolyRegressV3.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!