Computing inertia of a symmetric matrix

### 15.3.10 Computing inertia of a symmetric matrix

The inertia command computes the inertia of a real symmetric matrix, i.e. the number of positive, negative and zero eigenvalues, by performing LDL decomposition (see Section 15.3.9). It can also use the factorization for solving a system of linear equations if certain inertia-related conditions are satisfied.

- inertia takes one mandatory argument and one or two optional arguments:
  - A, a symmetric matrix of order n with real coefficients.
  - Optionally, B, a matrix of type m× n or a vector of length n.
  - Optionally, p0, an integer such that 0≤ p0≤ n.
  Note that inertia does not check whether A is symmetric.
- inertia(A) returns the list [p,n,z] where p, n and z are the numbers of positive, negative and zero eigenvalues of A, respectively.
- inertia(A,B ⟨,p0 ⟩) returns the sequence containing two elements: the list [p,n,z] and the solution X to the system AXT=BT in case z=0. If p0 is given, then X is not computed if p≠ p0 and an empty list is returned instead.
- The inertia of A is computed from the LDL factorization of A. The matrix X can be computed at a small cost once L and D are known. The purpose of the argument p0 is to prevent unnecessary computation if the matrix A has to be adjusted for the desired value of p before solving the system.

#### Examples

A:=[[1,-1,2],[-1,4,3],[2,3,-5]]

⎡ ⎢ ⎢ ⎣ |
1 | −1 | 2
−1 | 4 | 3
2 | 3 | −5
| ⎤ ⎥ ⎥ ⎦

inertia(A)

| ⎡ ⎣ | 2,1,0 | ⎤ ⎦

inertia(A,[[1,2,3],[4,5,6]])

| ⎡ ⎣ | 2,1,0 | ⎤ ⎦ | , |
⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ |
15
13
8
13
3
13
177
52
71
52
51
52
| ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦

If we set p0=1, then X is not computed.

inertia(A,[[1,2,3],[4,5,6]],1)

| ⎡ ⎣ | 2,1,0 | ⎤ ⎦ | , | ⎡ ⎣ | ⎤ ⎦