# How I can find the matrix $A$ of this quadratic form?

Let $(e_1,\ldots,e_n)$ the standard basis of $\mathbb R^n$ and we consider the quadratic form $$\Phi(x)=\sum_{1\le i<j\le n}(x_i-x_j)^2$$ How I can find the matrix $A$ of this quadratic form?

My try: I know that we can determinate the coefficient $A_{ij}$ of $A$ using the coefficient of $x_ix_j$ of $\Phi$. Thanks for help.

## 2 Answers

Unless I'm misunderstanding something I think this is pretty straightforward:

$$\sum_{1\le i<j\le n}(x_i-x_j)^2=(x_1-x_2)^2+(x_1-x_3)^2+\ldots+(x_1-x_n)^2+\ldots+(x_{n-1}-x_n)^2=$$

$$=x_1^2-2x_1x_2+x_2^2+\ldots+x_1^2-2x_1x_n+x_n^2+\ldots+x_{n-1}^2-2x_{n-1}x_n+x_n^2=$$

$$(n-1)\left[x_1^2+\ldots+x_n^2\right]-2\sum_{1\le i<j\le n}x_ix_j\;\;\ldots\ldots$$

We have $$\Phi(x)=\frac 12\sum_{i,j=1}^n(x_i-x_j)^2=\frac 12\left(2(n-1)\sum_{k=1}^nx_k^2-2\sum_{i\neq j}x_ix_j\right),$$ hence the matrix for the canonical basis is given by $A_{i,i}=n-1$ and $A_{i,j}=-1/2$ for $i\neq j$.