How sum work, vectors and matrices

I am having troubles understanding what is going on here. Would anyone be able to do this step by step with values so that I will be able to understand the SUM and how it works.

xi is in this case colum 1, and Matrix X is the entire thing.

Matrix X

Also note that looking at the large general matrix you it should have a diagonal with sum of squares and off-diagonal is the cross product.

Also to clarify XX(where 'is the transpose) is equal to the one above. This I am not able to understand.

To Clarify the question, It is stated in the book that X'X should be equal to the sumof xixi'. --> as shown in the picture. however if I take Matrix(as given above) X'X i get {{4,14},{14,54}}. When I try this with the sum function I am not able to get the same result, could someone please be so kind to take the effort writing this example out step by step.

• AUGH that is notation is terrible! I'm sorry you have to slog through that mess of summations. Dec 29, 2013 at 5:33
• The book skips a very important step. It should read: $\sum_1^N (\text{product of column and row vector}) = \sum_1^N (\text{matrix of products}) = \text{matrix of sums of products}$. The missing step is that the sum distributes inside the matrix (this is just because of how the addition of matrices is defined—you just add the individual components). Dec 29, 2013 at 6:45
• Could you please show how this is done with an example? Dec 29, 2013 at 7:17

The setup described below seems to be purely formal. But it is motivated by the underlying conceptual content, as explained in linear algebra courses.

A matrix $A=[a_{ik}]$ is with $m$ rows and $n$ columns is called an $(m\times n)$-matrix. When an $(m\times n)$ matrix $A$ and an $(n\times p)$-matrix $B$ are given (note the $n$ appearing twice here) then their product $AB$, an $(n\times p)$ matrix, is defined by $${\rm elm}_{jl}(AB):={\rm row}_j(A)\cdot {\rm col}_l(B):=\sum_{k=1}^n a_{jk}\>b_{kl}\qquad(1\leq j\leq m, \>1\leq l\leq p)\ .\tag{1}$$ Here the $\cdot$ denotes the usual scalar product between tuples of the same length.

An $n$-tuple ${\bf x}=(x_1,x_2,\ldots, x_n)\in{\mathbb R}^n$ is by convention considered as a column vector, i.e., an $(n\times 1)$-matrix, with the $x_k$ as entries, and one writes ${\bf x}'$ for the analogous row vector, i.e., the $(1\times n)$-matrix with the $x_k$ in its single row.

Given two vectors ${\bf x}$ and ${\bf y}$ both products ${\bf x}'{\bf y}$ and ${\bf x}{\bf y}'$ are defined since the "compatibility condition" is fulfilled in both cases. The result of the first multiplication is a $(1\times 1)$-matrix, which is the same as a number. This number is nothing else but the usual scalar product of the two vectors ${\bf x}, {\bf y}\in{\mathbb R}^n$.

The result of the second multiplication however is an $(n\times n)$-matrix whose elements according to $(1)$ are given by $${\rm elm}_{jl}({\bf x}{\bf y}')=\sum_{k=1}^1 {\bf x}_{jk}\>{\bf y}'_{kl}=x_j\>y_l\qquad(1\leq j\leq n, \>1\leq l\leq n)\ .\tag{2}$$ In your case you are given a list of $N$ vectors $${\bf x}_i=(x_{i.1},x_{i.2},\ldots, x_{i.K})\in{\mathbb R}^K\qquad(1\leq i\leq N)\ .$$ The index $i$ does not number any components, but denotes the position of the vector ${\bf x}_i$ in the list, and I refer to the components after the dot.

According to the above each product of the form ${\bf x}_i{\bf x}'_i$ $\>(1\leq i\leq N)\$ is a $(K\times K)$-matrix whose elements according to $(2)$ are given by $${\rm elm}_{jl}({\bf x}_i{\bf x}_i')=x_{i.j}\>x_{i.l}\qquad(1\leq j\leq K, \>1\leq l\leq K)\ .\tag{2}$$ The sum $S:=\sum_{i=1}^N{\bf x}_i{\bf x}_i'$ of these $N$ matrices is to be taken elementwise. Therefore it is again a $(K\times K)$-matrix, whose elements are given by $${\rm elm}_{jl}(S)=\sum_{i=1}^N x_{i.j}\>x_{i.l}\ ,$$ as displayed in your question.

Consider the following numerical example: We are given the two vectors (number triples) $${\bf x}_1:=(2,3,5),\quad {\bf x}_2:=(1,1,1)\ .$$ This corresponds to $N=2$ and $K=3$. Then $${\bf x}_1{\bf x}'_1=\left[\matrix{2\cr 3\cr 5\cr}\right]\>[2\ 3\ 5]= \left[\matrix{4&6&10\cr 6&9&15\cr 10&15&25\cr}\right]\ ,\qquad {\bf x}_2{\bf x}'_2=\left[\matrix{1\cr 1\cr 1\cr}\right]\>[1\ 1\ 1]= \left[\matrix{1&1&1\cr 1&1&1\cr 1&1&1\cr}\right]\ .$$ It follows that $$S=\sum_{i=1}^2 {\bf x}_i{\bf x}'_i=\left[\matrix{5&7&11\cr 7&10&16\cr 11&16&26\cr}\right]\ .$$ The "$10$" in the center of the matrix $S$ results from $9+1=x_{1.2}^2+x_{2.2}^2$, as indicated in the displayed source.

• Please would you be able to show this by the numbers that I have posted? Dec 30, 2013 at 12:10
• How do I go about computing the sum of these N matrices? You see that X´X gives me a 2 by 2 matrix, while the sum xi.xi´gives me a 3 by 3 matrix. Where I distribute the sum inside the matrix and where the values of the diagonal is squared. I am not however able to see how the sum works to get me to a 2 by 2 matrix. Hope you are able to help. Regards Aleksander Dec 30, 2013 at 12:35
• @ALEXANDER: See my edit. I don't see $2$ and $3$ in the displayed source, but $K$ and $N$, as in my text. Dec 30, 2013 at 15:23
• Sorry I thought that I got it but no,, I see that if the sum goes from 1 to 3 then xijxil would be 2*2+3*3+4*4+5*5 = would equal to 54. But I am not able to see how I get 4 and 14 In {{54,14},{14,4}}. I am almost giving up now. Could you please go by the numbers? Dec 31, 2013 at 7:51
• @ALEXANDER: See my appendix. This is my last word in this matter. Dec 31, 2013 at 9:20

We know that a column vector multiplied by a row vector is a matrix (not to be confused with the row vector by a column vector, which is the inner product). The transpose of a vector essentially 'converts' it into another alignment of vector. Thus:

$$\vec X = \left( \begin{array}{ccc} a \\ b \\ c \\ \end{array} \right) \\ \vec X' = \left( \begin{array}{ccc} a & b & c\end{array} \right)$$

Reviewing sigma notation, we're adding up all the terms $n$ times, and $i$ counts it. It repeats each time until the $i$ is equal to the initial $i_0 + n$. Thus, for $X\cdot X'$, we multiply the two vectors and distribute the sigma to each component.

• I do not get it, in the book it states that X´X is equal to sum[xi*xi] Dec 29, 2013 at 5:56
• Would you be able to show it step by step with the numbers I have given. When I calculate XX I get {{54,14},{14,4}} however when trying to do it with sum I get it all wrong. Dec 29, 2013 at 5:58

Given two column vectors a and b, the Euclidean inner product and outer product are the simplest special cases of the matrix product, by transposing the column vectors into row vectors.

The inner product is the normal product which will yield a scalar.

The outer/ tensor product however,is a row vector multiplied on the left by a column vector: see the link below :-