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 CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by