Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to compute the matrix of differences of a vector, just like here in section "Matrix of differences". Is that actually correct? I thought that, in order to add up (or subtract) two vector/matrices they had to have the same dimensions.

share|cite|improve this question
up vote 1 down vote accepted

That's not a "real" matrix/vector difference. It's just a particular operation, a non-standard way to represent inside a matrix all the differences between the components of two vectors.

If you want to write it using correct/standard matrix operations, you could write

$A = u x^t - y u^t $

where $u^t = (1, 1, 1... )$ is an all-ones vector, and $x$, $y$, are your vectors, represented as column matrices.

share|cite|improve this answer

It is correct as written, but it's a notational problem. Usually one uses a symbol to denote that we are interested in the matrix of differences, perhaps something like $(u,v)_{diff} = $ some matrix.

On the other hand, you are correct - when adding or subtracting matrices, they should be of the same dimension. I would say that his use of the simple minus sign is a slight abuse of notation here, but that happens from time to time.

share|cite|improve this answer

You are not "really" taking the difference of two matrices, at least not in the sense of addition of matrices (which usually requires the two matrices to be the same size).

Instead, the "$-$" symbol here represents a different operation (alas for the confusion), in which you consider to $n$-tuples and construct a matrix whose entries are all possible differences. So the $-$ symbol you are seeing is not the symbol that represents subtraction of matrices in the usual sense.

If we use a different symbol, say $\ominus$, it might be clearer. We define $\ominus$ as an operation that takes an $n\times 1$ vector and a $1\times n$ vector, and whose result is an $n\times n$ matrix, as follows: $$\left(\begin{array}{c}a_1\\ \ldots\\ a_n\end{array}\right)\ominus \left(b_1,\ldots,b_n\right) = \left(\begin{array}{cccc} a_1-b_1 & a_1-b_2 & \cdots & a_1-b_n\\ a_2-b_1 & a_2-b_2 & \cdots & a_2-b_n\\ \vdots & \vdots & \ddots & \vdots\\ a_n-b_1 & a_n-b_2 & \cdots & a_n-b_n \end{array}\right);$$ that is, the $ij$th entry of $\mathbf{v}\ominus \mathbf{w}$ is $v_i-w_j$.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.