# 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$. Oct 22 '18 at 10:03
• Do you need just an expression to write somewhere or do you need an efficient method of computing this matrix? Oct 22 '18 at 10:38
• 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 Oct 22 '18 at 10:43
• @YuriyS Thanks for the R code. I directly use the expression for calculation in Matlab. For my needs, this is sufficiently efficient. For documentation, I was just looking for an easier to understand expression. Oct 22 '18 at 11:33
• @user10354138 I think index notation does the job. Thank you! Oct 22 '18 at 11:33

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$$.