llbilgekaganll
llbilgekaganll

Reputation: 21

Matlab left - division in vectors?

x=[1;2;3]

x =

 1
 2
 3

y=[4;5;6]

y =

 4
 5
 6

x\y

ans =

2.2857

How did Matlab find that result ? (I searched many forums but I did not understand what they told.I would like to know the algorithm which gave this result.)

Upvotes: 2

Views: 1734

Answers (2)

Autonomous
Autonomous

Reputation: 9075

From MATLAB documentation of \:

If A is an M-by-N matrix with M < or > N and B is a column vector with M components, or a matrix with several such columns, then X = A\B is the solution in the least squares sense to the under- or overdetermined system of equations A*X = B.

Here your system is not under/over-determined. Since both have 3 rows. So you can visualize your equation as:

xM=y
M=inv(x)*y

Now, since your matrix is not square, it will calculate the pseudo-inverse using SVD. Therefore,

M=pinv(x)*y;

You will get value of M as 2.2857.

Another explanation can be: It will give you the solution of xM=y in the sense of least squares. You can verify this as follows:

M=lsqr(x,y)

This will give you the value of M = 2.2857.

You can always do help \ in MATLAB command window to get more information.

You are encouraged to check more details about the least squares and pseudo-inverse.

Upvotes: 5

Daniel Williams
Daniel Williams

Reputation: 8885

This documentation should explain it

http://www.mathworks.com/help/matlab/ref/mrdivide.html

Here is a link to the algorithm

http://www.maths.lth.se/na/courses/NUM115/NUM115-11/backslash.html

You can see the source inside matlab much more easily though. (I don't have it locally so I can't check but the source of a lot of matlab functions is available inside matlab)

Upvotes: -1

Related Questions