In linear algebra, the Gram matrix (or Gramian matrix, Gramian) of a set of vectors [math]\displaystyle{ v_1,\dots, v_n }[/math] in an inner product space is the Hermitian matrix of inner products, whose entries are given by [math]\displaystyle{ G_{ij}=\langle v_i, v_j \rangle }[/math].[1]
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.
For finite-dimensional real vectors in [math]\displaystyle{ \mathbb{R}^n }[/math] with the usual Euclidean dot product, the Gram matrix is simply [math]\displaystyle{ G = V^\mathrm{T} V }[/math], where [math]\displaystyle{ V }[/math] is a matrix whose columns are the vectors [math]\displaystyle{ v_k }[/math]. For complex vectors in [math]\displaystyle{ \mathbb{C}^n }[/math], [math]\displaystyle{ G = V^H V }[/math], where [math]\displaystyle{ V^H }[/math] is the conjugate transpose of [math]\displaystyle{ V }[/math].
Given square-integrable functions [math]\displaystyle{ \{\ell_i(\cdot),\,i=1,\dots,n\} }[/math] on the interval [math]\displaystyle{ [t_0,t_f] }[/math], the Gram matrix [math]\displaystyle{ G=[G_{ij}] }[/math] is:
For any bilinear form [math]\displaystyle{ B }[/math] on a finite-dimensional vector space over any field we can define a Gram matrix [math]\displaystyle{ G }[/math] attached to a set of vectors [math]\displaystyle{ v_1,\dots, v_n }[/math] by [math]\displaystyle{ G_{ij} = B(v_i,v_j) }[/math]. The matrix will be symmetric if the bilinear form [math]\displaystyle{ B }[/math] is symmetric.
This generalizes the classical surface integral of a parametrized surface [math]\displaystyle{ \phi:U\to S\subset \mathbb{R}^3 }[/math] for [math]\displaystyle{ (x,y)\in U\subset\mathbb{R}^2 }[/math]:
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:
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 [math]\displaystyle{ v_i }[/math] are linearly independent (that is, [math]\displaystyle{ \textstyle\sum_i x_i v_i \neq 0 }[/math] for all [math]\displaystyle{ x }[/math]).[1]
Given any positive semidefinite matrix [math]\displaystyle{ M }[/math], one can be decompose it as:
where [math]\displaystyle{ B^* }[/math] is the conjugate transpose of [math]\displaystyle{ B }[/math] (or [math]\displaystyle{ M = B^\textsf{T} B }[/math] in the real case). Here [math]\displaystyle{ B }[/math] is a [math]\displaystyle{ k \times n }[/math] matrix, where [math]\displaystyle{ k }[/math] is the rank of [math]\displaystyle{ M }[/math]. Various ways to obtain such a decomposition include computing the Cholesky decomposition or taking the non-negative square root of [math]\displaystyle{ M }[/math].
The columns [math]\displaystyle{ b^{(1)},\dots,b^{(n)} }[/math] of [math]\displaystyle{ B }[/math] can be seen as n vectors in [math]\displaystyle{ \mathbb{C}^k }[/math] (or k-dimensional Euclidean space [math]\displaystyle{ \mathbb{R}^k }[/math], in the real case). Then
where the dot product [math]\displaystyle{ a \cdot b = \sum_{\ell=1}^k \overline{a_\ell} b_\ell }[/math] is the usual inner product on [math]\displaystyle{ \mathbb{C}^k }[/math].
Thus a Hermitian matrix [math]\displaystyle{ M }[/math] is positive semidefinite if and only if it is the Gram matrix of some vectors [math]\displaystyle{ b^{(1)},\dots,b^{(n)} }[/math]. Such vectors are called a vector realization of [math]\displaystyle{ M }[/math]. The infinite-dimensional analog of this statement is Mercer's theorem.
If [math]\displaystyle{ M }[/math] is the Gram matrix of vectors [math]\displaystyle{ v_1,\dots,v_n }[/math] in [math]\displaystyle{ \mathbb{R}^k }[/math], then applying any rotation or reflection of [math]\displaystyle{ \mathbb{R}^k }[/math] (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 [math]\displaystyle{ k \times k }[/math] orthogonal matrix [math]\displaystyle{ Q }[/math], the Gram matrix of [math]\displaystyle{ Q v_1,\dots, Q v_n }[/math] is also [math]\displaystyle{ M }[/math].
This is the only way in which two real vector realizations of [math]\displaystyle{ M }[/math] can differ: the vectors [math]\displaystyle{ v_1,\dots,v_n }[/math] are unique up to orthogonal transformations. In other words, the dot products [math]\displaystyle{ v_i \cdot v_j }[/math] and [math]\displaystyle{ w_i \cdot w_j }[/math] are equal if and only if some rigid transformation of [math]\displaystyle{ \mathbb{R}^k }[/math] transforms the vectors [math]\displaystyle{ v_1,\dots,v_n }[/math] to [math]\displaystyle{ w_1,\dots,w_n }[/math] 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 [math]\displaystyle{ v_1,\dots,v_n }[/math] is equal to the Gram matrix of vectors [math]\displaystyle{ w_1,\dots,w_n }[/math] in [math]\displaystyle{ \mathbb{C}^k }[/math], then there is a unitary [math]\displaystyle{ k \times k }[/math] matrix [math]\displaystyle{ U }[/math] (meaning [math]\displaystyle{ U^* U = I }[/math]) such that [math]\displaystyle{ v_i = U w_i }[/math] for [math]\displaystyle{ i = 1,\dots,n }[/math].[3]
The Gram determinant or Gramian is the determinant of the Gram matrix:
If [math]\displaystyle{ x_1, \cdots, x_n }[/math] are vectors in [math]\displaystyle{ \mathbb{R}^n }[/math], 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