2
$\begingroup$

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?

Thank you for your help!

$\endgroup$
  • 2
    $\begingroup$ 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$. $\endgroup$ – user10354138 Oct 22 '18 at 10:03
  • $\begingroup$ Do you need just an expression to write somewhere or do you need an efficient method of computing this matrix? $\endgroup$ – Yuriy S Oct 22 '18 at 10:38
  • $\begingroup$ 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 $\endgroup$ – Yuriy S Oct 22 '18 at 10:43
  • $\begingroup$ @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. $\endgroup$ – vkeller Oct 22 '18 at 11:33
  • $\begingroup$ @user10354138 I think index notation does the job. Thank you! $\endgroup$ – vkeller Oct 22 '18 at 11:33
0
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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