Gramian matrix

In linear algebra, the **Gram matrix** (or **Gramian matrix**, **Gramian**) of a set of vectors

v
1

,
…
,

v
n

{\displaystyle v\_1,\dots,v\_n}

 in an inner product space is the Hermitian matrix of inner products, whose entries are given by

G

i
j

=
⟨

v
i

,

v
j

⟩

{\displaystyle G\_{ij}=\langle v\_i, v\_j \rangle}

.

An important application is to compute linear independence: a set of vectors are linearly independent if and only if the Gram determinant (the determinant of the Gram matrix) is non-zero.

It is named after Jørgen Pedersen Gram.

## Examples

For finite-dimensional real vectors in

R

n

{\displaystyle \R^n}

 with the usual Euclidean dot product, the Gram matrix is simply

# G

V

T

V

{\displaystyle G = V^\mathrm{T} V}

, where

V

{\displaystyle V}

 is a matrix whose columns are the vectors

v
k

{\displaystyle v\_k}

. For complex vectors in

C

n

{\displaystyle \C^n}

,

# G

V
H

V

{\displaystyle G = V^H V}

, where

V
H

{\displaystyle V^H}

 is the conjugate transpose of

V

{\displaystyle V}

.

Given square-integrable functions

{

ℓ
i

(
⋅
)
,

# i
1
,
…
,
n
}

{\displaystyle \{\ell\_i(\cdot),\,i=1,\dots,n\}}

 on the interval

[

t
0

,

t
f

]

{\displaystyle [t\_0,t\_f]}

, the Gram matrix

# G
[

G

i
j

]

{\displaystyle G=[G\_{ij}]}

 is:

G

i
j

=

∫

t
0

t
f

ℓ
i

(
τ
)

ℓ
j

¯

(
τ
)

d
τ
.

{\displaystyle G\_{ij}=\int\_{t\_0}^{t\_f} \ell\_i(\tau)\bar{\ell\_j}(\tau)\, d\tau. }

For any bilinear form

B

{\displaystyle B}

 on a finite-dimensional vector space over any field we can define a Gram matrix

G

{\displaystyle G}

 attached to a set of vectors

v
1

,
…
,

v
n

{\displaystyle v\_1,\dots,v\_n}

 by

G

i
j

=
B
(

v
i

,

v
j

)

{\displaystyle G\_{ij} = B(v\_i,v\_j)}

. The matrix will be symmetric if the bilinear form

B

{\displaystyle B}

 is symmetric.

### Applications

* In Riemannian geometry, given an embedded

k

{\displaystyle k}

-dimensional Riemannian manifold

M
⊂

R

n

{\displaystyle M\subset \mathbb{R}^n}

 and a coordinate chart

ϕ
:
U
→
M

{\displaystyle \phi:U\to M}

 for

(

x
1

,
…
,

x
k

)
∈
U
⊂

R

k

{\displaystyle (x\_1,\ldots,x\_k)\in U\subset\mathbb{R}^k}

, the volume form

ω

{\displaystyle \omega}

 on

M

{\displaystyle M}

 induced by the embedding may be computed using the Gramian of the coordinate tangent vectors:

# ω

det
G

d

x
1

⋯
d

x
k

,

# G

[

⟨

∂
ϕ

∂

x
i

,

∂
ϕ

∂

x
j

⟩

]

.

{\displaystyle \omega = \sqrt{\det G}\ dx\_1\cdots dx\_k,\quad G = \left[\left\langle \tfrac{\partial\phi}{\partial x\_i},\tfrac{\partial\phi}{\partial x\_j}\right\rangle\right].}

This generalizes the classical surface integral of a parametrized surface

ϕ
:
U
→
S
⊂

R

3

{\displaystyle \phi:U\to
S\subset \mathbb{R}^3}

 for

(
x
,
y
)
∈
U
⊂

R

2

{\displaystyle (x,y)\in U\subset\mathbb{R}^2}

:

∫
S

f

d
A

=

∬
U

f
(
ϕ
(
x
,
y
)
)

∂
ϕ

∂
x

×

∂
ϕ

∂
y

d
x

d
y
.

{\displaystyle \int\_S f\ dA \ =\ \iint\_U f(\phi(x,y))\, \left|\tfrac{\partial\phi}{\partial x}\,{\times}\,\tfrac{\partial\phi}{\partial y}\right|\, dx\, dy.}

* If the vectors are centered random variables, the Gramian is approximately proportional to the **covariance matrix**, with the scaling determined by the number of elements in the vector.
* In quantum chemistry, the Gram matrix of a set of basis vectors is the **overlap matrix**.
* In control theory (or more generally systems theory), the **controllability Gramian** and **observability Gramian** determine properties of a linear system.
* Gramian matrices arise in covariance structure model fitting (see e.g., Jamshidian and Bentler, 1993, Applied Psychological Measurement, Volume 18, pp. 79–94).
* In the finite element method, the Gram matrix arises from approximating a function from a finite dimensional space; the Gram matrix entries are then the inner products of the basis functions of the finite dimensional subspace.
* In machine learning, kernel functions are often represented as Gram matrices.
* Since the Gram matrix over the reals is a symmetric matrix, it is diagonalizable and its eigenvalues are non-negative. The diagonalization of the Gram matrix is the singular value decomposition.

## Properties

### Positive-semidefiniteness

The Gram matrix is symmetric in the case the real product is real-valued; it is Hermitian in the general, complex case by definition of an inner product.

The Gram matrix is positive semidefinite, and every positive semidefinite matrix is the Gramian matrix for some set of vectors.
The fact that the Gramian matrix is positive-semidefinite can be seen from the following simple derivation:

x
T

G

# x

∑

i
,
j

x
i

x
j

⟨

v
i

,

v
j

⟩

=

∑

i
,
j

⟨

x
i

v
i

,

x
j

v
j

⟩

=

⟨

∑
i

x
i

v
i

,

∑
j

x
j

v
j

⟩

=

‖

∑
i

x
i

v
i

‖

2

≥
0
.

{\displaystyle x^\text{T} \mathbf{G} x = \sum\_{i,j}x\_i x\_j\left\langle v\_i,v\_j \right\rangle = \sum\_{i,j}\left\langle x\_i v\_i, x\_j v\_j \right\rangle =
\left\langle \sum\_i x\_i v\_i, \sum\_j x\_j v\_j \right\rangle =\left\| \sum\_i x\_i v\_i \right\|^2 \geq 0 .}

The first equality follows from the definition of matrix multiplication, the second and third from the bi-linearity of the inner-product, and the last from the positive definiteness of the inner product.
Note that this also shows that the Gramian matrix is positive definite if and only if the vectors

v
i

{\displaystyle v\_i}

 are linearly independent (that is,

∑
i

x
i

v
i

≠
0

{\displaystyle \textstyle\sum\_i x\_i v\_i \neq 0}

 for all

x

{\displaystyle x}

).

### Finding a vector realization

See also: Positive definite matrix#Decomposition
Given any positive semidefinite matrix

M

{\displaystyle M}

, one can be decompose it as:

# M

B
∗

B

{\displaystyle M = B^\* B}

,
where

B
∗

{\displaystyle B^\*}

 is the conjugate transpose of

B

{\displaystyle B}

 (or

# M

B
T

B

{\displaystyle M = B^\text{T} B}

 in the real case).
Here

B

{\displaystyle B}

 is a

k
×
n

{\displaystyle k \times n}

 matrix, where

k

{\displaystyle k}

 is the rank of

M

{\displaystyle M}

.
Various ways to obtain such a decomposition include computing the Cholesky decomposition or taking the non-negative square root of

M

{\displaystyle M}

.

The columns

b

(
1
)

,
…
,

b

(
n
)

{\displaystyle b^{(1)},\dots,b^{(n)}}

 of

B

{\displaystyle B}

 can be seen as *n* vectors in

C

k

{\displaystyle \mathbb{C}^k}

 (or *k*-dimensional Euclidean space

R

k

{\displaystyle \mathbb{R}^k}

, in the real case).
Then

M

i
j

=

b

(
i
)

⋅

b

(
j
)

{\displaystyle M\_{ij} = b^{(i)} \cdot b^{(j)}}

where the dot product

a
⋅

# ℓ
1

k

a
ℓ

¯

b
ℓ

{\displaystyle a \cdot b = \sum\_{\ell=1}^k \overline{a\_\ell} b\_\ell}

 is the usual inner product on

C

k

{\displaystyle \mathbb{C}^k}

.

Thus a Hermitian matrix

M

{\displaystyle M}

 is positive semidefinite if and only if it is the Gram matrix of some vectors

b

(
1
)

,
…
,

b

(
n
)

{\displaystyle b^{(1)},\dots,b^{(n)}}

.
Such vectors are called a **vector realization** of

M

{\displaystyle M}

.
The infinite-dimensional analog of this statement is Mercer's theorem.

### Uniqueness of vector realizations

If

M

{\displaystyle M}

 is the Gram matrix of vectors

v
1

,
…
,

v
n

{\displaystyle v\_1,\dots,v\_n}

 in

R

k

{\displaystyle \mathbb{R}^k}

,
then applying any rotation or reflection of

R

k

{\displaystyle \mathbb{R}^k}

 (any orthogonal transformation, that is, any Euclidean isometry preserving 0) to the sequence of vectors results in the same Gram matrix.
That is, for any

k
×
k

{\displaystyle k \times k}

 orthogonal matrix

Q

{\displaystyle Q}

, the Gram matrix of

Q

v
1

,
…
,
Q

v
n

{\displaystyle Q v\_1,\dots, Q v\_n}

 is also

M

{\displaystyle M}

.

This is the only way in which two real vector realizations of

M

{\displaystyle M}

 can differ: the vectors

v
1

,
…
,

v
n

{\displaystyle v\_1,\dots,v\_n}

 are unique up to orthogonal transformations.
In other words, the dot products

v
i

⋅

v
j

{\displaystyle v\_i \cdot v\_j}

 and

w
i

⋅

w
j

{\displaystyle w\_i \cdot w\_j}

 are equal if and only if some rigid transformation of

R

k

{\displaystyle \mathbb{R}^k}

 transforms the vectors

v
1

,
…
,

v
n

{\displaystyle v\_1,\dots,v\_n}

 to

w
1

,
…
,

w
n

{\displaystyle w\_1,\dots,w\_n}

 and 0 to 0.

The same holds in the complex case, with unitary transformations in place of orthogonal ones.
That is, if the Gram matrix of vectors

v
1

,
…
,

v
n

{\displaystyle v\_1,\dots,v\_n}

 is equal to the Gram matrix of vectors

w
1

,
…
,

w
n

{\displaystyle w\_1,\dots,w\_n}

 in

C

k

{\displaystyle \mathbb{C}^k}

,
then there is a unitary

k
×
k

{\displaystyle k \times k}

 matrix

U

{\displaystyle U}

 (meaning

U
∗

# U
I

{\displaystyle U^\* U = I}

) such that

v
i

=
U

w
i

{\displaystyle v\_i = U w\_i}

 for

# i
1
,
…
,
n

{\displaystyle i = 1,\dots,n}

.

### Other properties

* The Gram matrix of any orthonormal basis is the identity matrix.
* The rank of the Gram matrix of vectors in

R

k

{\displaystyle \mathbb{R}^k}

 or

C

k

{\displaystyle \mathbb{C}^k}

 equals the dimension of the space spanned by these vectors.

## Gram determinant

The **Gram determinant** or **Gramian** is the determinant of the Gram matrix:

G
(

x
1

,
…
,

x
n

# )

⟨

x
1

,

x
1

⟩

⟨

x
1

,

x
2

⟩

…

⟨

x
1

,

x
n

⟩

⟨

x
2

,

x
1

⟩

⟨

x
2

,

x
2

⟩

…

⟨

x
2

,

x
n

⟩

⋮

⋮

⋱

⋮

⟨

x
n

,

x
1

⟩

⟨

x
n

,

x
2

⟩

…

⟨

x
n

,

x
n

⟩

.

{\displaystyle G(x\_1,\dots, x\_n)=\begin{vmatrix} \langle x\_1,x\_1\rangle & \langle x\_1,x\_2\rangle &\dots & \langle x\_1,x\_n\rangle\\
 \langle x\_2,x\_1\rangle & \langle x\_2,x\_2\rangle &\dots & \langle x\_2,x\_n\rangle\\
\vdots&\vdots&\ddots&\vdots\\
 \langle x\_n,x\_1\rangle & \langle x\_n,x\_2\rangle &\dots & \langle x\_n,x\_n\rangle\end{vmatrix}.}

If

x
1

,
⋯
,

x
n

{\displaystyle x\_1, \cdots, x\_n}

 are vectors in

R

n

{\displaystyle \R^n}

, then it is the square of the *n*-dimensional volume of the parallelotope formed by the vectors. In particular, the vectors are linearly independent if and only if the parallelotope has nonzero *n*-dimensional volume, if and only if Gram determinant is nonzero, if and only if the Gram matrix is nonsingular.

The Gram determinant can also be expressed in terms of the exterior product of vectors by

G
(

x
1

,
…
,

x
n

# )
‖

x
1

∧
⋯
∧

x
n

‖
2

.

{\displaystyle G(x\_1,\dots,x\_n) = \| x\_1\wedge\cdots\wedge x\_n\|^2.}