Problem with linear least squares, '\' does not work, Why ?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
M Bedir Tapkan
am 23 Mär. 2018
Bearbeitet: Star Strider
am 23 Mär. 2018
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
0 Kommentare
Akzeptierte Antwort
Star Strider
am 23 Mär. 2018
Bearbeitet: Star Strider
am 23 Mär. 2018
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Linear Algebra finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!