# Looking for more compact expression to generate matrix from vector

Given a vector $$v = \begin{pmatrix} v_1 \\ v_2 \\ \vdots \\ v_n \end{pmatrix}$$, I need to generate a matrix $$A$$

$$A = \begin{pmatrix} 0 & v_1 + v_2 & \cdots & v_1 + v_n \\ v_2 + v_1 & 0 & & v_2 + v_n \\ \vdots & & \ddots & \vdots \\ v_n + v_1 & v_n + v_2 & \cdots & 0 \\ \end{pmatrix}$$

Currently, I describe this as

$$A = (v J_{1,n} + J_{n,1} v^{T}) \circ (J_{n,n} - I_n)$$

$$J_{n,m}$$ is an $$n\times m$$ matrix of ones and $$\circ$$ is the element-wise product.

Is there a more compact expression to generate $$A$$, potentially using some special product?

• There is always the option of writing something like $A_{ij}=v_i+v_j-2\delta_{ij}v_i$, or using your notation, $A=vJ_{1,n}+J_{n,1}v^T-2\operatorname{diag}v$. – user10354138 Oct 22 '18 at 10:03
• For example in R, you can simply write A <- outer(v, v, FUN="+")-2*diag(v) which for any numeric vector v efficiently computes the matrix A – Yuriy S Oct 22 '18 at 10:43
As stated in comments, you have $$A_{ij}=v_i+v_j-2\delta_{ij}v_i$$ which is probably most obvious and naïve method of generating $$A$$.