Solving Linear Equation of two column vectors

135 Views Asked by At

consider following examples of two MatLab formatted column vectors x1 and x2 and a scalar result x3 per each example:

first example

x1 = [1;1;1];
x2 = [3;3;3];
x3 = x1\x2; % which is same as x3 = mldivide(x1,x2)

x3 results in 3.


Now second example

x1 = [0.5;1;1];
x2 = [3;3;3];
x3 = x1\x2; % which is same as x3 = mldivide(x1,x2)

x3 results in 3.3333.


And a 3rd example

x1 = [1;2;3];
x2 = [4;5;6];
x3 = x1\x2; % which is same as x3 = mldivide(x1,x2)

Here x3 results in 2.2857.


Could you please tell me what is the solution process to get that scalar value in the second and third example?

I understand solving examples such as this one:

A =

 1     1     1     1
 0     2     5    -1
 2     5    -1     1
 2     2     2     1

B =

 7    14
-5   -10
28    56
13    26

Which result in X (A\B)

X =

 5    10
 3     6
-2    -4
 1     2

But the second and third one leave me puzzled right now. And I have tried to get to the result myself as well as have searched the web. But since I am asking here it is obvious that I have not found the solution myself. :-)

I am not a Math expert. And yes, I am not a genius. But I am interested in Math and solving "mysteries".

Thank you very much for any help!

1

There are 1 best solutions below

1
On

The backslash operator in Matlab, when used as A\B, attempts to find a solution to the equation $Ax=B$. If an exact solution can be found, (usually a close approximation of) this solution is returned. If this is not possible, the solution $x$ minimizing the 2-norm of the error vector $Ax-B$ is returned. This solution is calculated by finding the pseudo-inverse of $A$ and multiplying it with $B$. More precisely, the backslash operator returns:

$$x_{\text{sol}} = \text{argmin}_x \left\|Ax-B\right\|_2$$

and this vector $x_{\text{sol}}$ is calculated by multiplying the pseudo-inverse of $A$ with $B$:

$$x_{\text{sol}} = (A^TA)^{-1}A^TB$$

Calculating the pseudo-inverse in a numerically stable way can be achieved in Matlab with the pinv command.

In your first example, an exact solution can be found, hence it is returned (close to machine precision probably). In the second and third example, an exact solution cannot be found, and as such the solution might seem a little bit odd at first glance, but it is the solution $x$ minimizing the norm of $Ax-B$.