Problem with linear least squares, '\' does not work, Why ?

6 ビュー (過去 30 日間)
M Bedir Tapkan
M Bedir Tapkan 2018 年 3 月 23 日
編集済み: Star Strider 2018 年 3 月 23 日
Hi,
I have really simple question that I have to accomplish. I have couple lines of equations, all I want to do is solve these by using least squares. Question is in the format;
x + y = 4
-2x + 4y = 11
5x - 11y = -21
3x - 13y = -29
-4x - 16y = -41
All looks ok... I already checked the documentation and found the function that will exactly solve this type of problems: mldivide, \
As it states on description "If A is a rectangular m-by-n matrix with m ~= n, and B is a matrix with m rows, then A\B returns a least-squares solution to the system of equations A*x= B"
I am getting some crazy results when I use this. Here is how I tried... to solve:
a = [1 1; -2 3; 5 -11; 3 -13; -4 -16]
b = [4; 11; -21; -29; -41]
x = a\b
The result is weird (or I don't know if I am missing something)
x
Outputs:
x =
0.67992
2.38273
And,
a * x
Outputs:
3.0626
5.7883
-22.8104
-28.9357
-40.8433

採用された回答

Star Strider
Star Strider 2018 年 3 月 23 日
編集済み: Star Strider 2018 年 3 月 23 日
The key to understanding what the mldivide,\ function is doing here is ‘least-squares solution’.
You have an overdetermined system (more equations than unknowns), so mldivide computes a least-squares solution to your system.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by