how can I solve a over deterministic system with least square method?

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.

 採用された回答

John D'Errico
John D'Errico 2014 年 8 月 3 日
編集済み: John D'Errico 2014 年 8 月 3 日

1 投票

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 件のコメント

Ahmet Cecen
Ahmet Cecen 2014 年 8 月 3 日
Every regression code out there is eventually using the one liner you suggest one way or another. The "fancy" part of it is that they have lots of peripheral functionality built in for you instead of you having to figure them out yourself, like goodness of fit measures, confidence levels etc. Use whichever seems more your style I guess.
John D'Errico
John D'Errico 2014 年 8 月 3 日
編集済み: John D'Errico 2014 年 8 月 3 日
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
Ahmet Cecen 2014 年 8 月 4 日
I stand corrected with the one liners comment. I did my own survey and apparently many use other methods. +1 more bump.

サインインしてコメントする。

その他の回答 (1 件)

Ahmet Cecen
Ahmet Cecen 2014 年 8 月 3 日

0 投票

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.

カテゴリ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by