Problem with linear least squares, '\' does not work, Why ?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
M Bedir Tapkan
el 23 de Mzo. de 2018
Editada: Star Strider
el 23 de Mzo. de 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 comentarios
Respuesta aceptada
Star Strider
el 23 de Mzo. de 2018
Editada: Star Strider
el 23 de Mzo. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Linear Algebra en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!