# Matlab, operator A\B

What is the result of the operation A\B, where A(1, m) and B (1, m)?

In the manual it is written:

A\B returns a least-squares solution to the system of equations A*x= B.


So it means x = inv (A'*A)*A'*B? However, the matrix A'*A is singular...

Let us suppose:

A=[1 2 3]
B=[6 7 6]


Then

A\B

0         0         0
0         0         0
2.0000    2.3333    2.0000


If ve use MLS:

C = inv (A'*A)   singular matrix
C = pinv(A'*A)

0.0051    0.0102    0.0153
0.0102    0.0204    0.0306
0.0153    0.0306    0.0459

D= C*A'*B

0.4286    0.5000    0.4286
0.8571    1.0000    0.8571
1.2857    1.5000    1.2857


So results A\B and inv (A'*A)*A'*B are different...

-

## 2 Answers

In the interesting cases I knew before answering this question -the ones which appear in real problems I'm aware of-, the matrix $A$ is just the opposite of the one you've chosen: it usually has (way far) more rows than columns (see overdetermined system) and those columns are linearly independent vectors. Let's call them $a_1, \dots , a_n$:

$$A = (a_1 \dots a_n) \ .$$

Then $A^tA$ is the matrix of dot products

$$A^tA = \begin{pmatrix} a_1\cdot a_1 & \dots & a_1\cdot a_n \\ \vdots & \vdots & \vdots \\ a_n\cdot a_1 & \dots & a_n\cdot a_n \end{pmatrix}$$

which is always non-singular.

EDIT. In your case, your matrix $A$ has three non-linearly independent columns. All of your systems $x +2y + 3z = 6, 7, 6$ have infinitely many solutions. Matlab choses one of them. For instance, for the first system $x + 2y + 3z = 6$, my Matlab gives me $(0,0,2)$ as a solution an explains to us

help \ backslash

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. The effective rank, K, of A is determined from the QR decomposition with pivoting. A solution X is computed which has at most K nonzero components per column. If K < N this will usually not be the same solution as PINV(A)*B.

So, indeed, Matlab has given a solution with at most $K=1 = \mathrm{rank}(A)$ nonzero components per column. Otherwise said, if I'm not wrong, Matlab has solved the linear system $x + 2y + 3z = 6, x= 0, y = 0$.

-
@ Augusti: But A'*A = [1 2 3; 2 4 6; 3 6 9] is singular... – justik Nov 14 '12 at 15:22
Because the "vectors" $1$, $2$ and $3$ are NOT linearly independent: indeed $3 = 1 + 2$. :-) – a.r. Nov 14 '12 at 15:29
Yes, you are right. I am computing apseudoinverse matrix using the Goodall algorithm based on QR decomposition. The vector A is linearly dependent in general case... So my question is what Matlab computes in this case.... – justik Nov 14 '12 at 15:38
Since I hadn't enough room here, I've posted my answer as an EDIT. – a.r. Nov 14 '12 at 17:19
@ Agusti. Thanks for your answer.... – justik Nov 14 '12 at 19:07

If you have $A$ and $B$ as both row vectors, then C=A\B computes the matrix $C$ such that $$C=A\backslash B \implies AC=B.$$

Recognize that since $A$ and $B$ are $1\times m$ row vectors, $C$ will be an $m\times m$ matrix. This matrix is not unique. One way to construct such a matrix is to zero out all but one of the rows. Say the $k$th row is non-zero. Populate the entry in the $i$th column such that $C_{ki}$ is equal to $b_i/a_k$. Then, your vector-matrix multiplication yields, for the $i$th entry of the resulting vector, the product

$$\sum_{n=1}^m a_n C_{ni} = a_kC_{ki} = b_i$$

because $C_{ni} = 0$ if $n \neq k$.

This result, as it turns out, is quite uninteresting.

-