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

5 次查看(过去 30 天)
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