# Computing inertia of a symmetric matrix: inertia

### 5.49.10 Computing inertia of a symmetric matrix: inertia

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 5.49.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.
  - B (optional), a matrix of type m× n or a vector of length n.
  - p0 (optional), an integer such that 0≤ p0≤ n.
- If called with a single argument A, inertia returns the triple [p,n,z] where p, n and z are the numbers of positive, negative and zero eigenvalues of A, respectively.
- If called with arguments A and B, inertia returns the sequence containing two elements: the triple [p,n,z] and the solution X to the equation AXT=BT in case z=0.
- If called with three arguments, it returns the sequence containing [p,n,z] and X, but the latter is not computed if p≠ p0.
- inertia computes the inertia of A by computing the LDL factorization of A. The matrix X can be computed with small cost once L and D are known.
- Note that inertia does not check whether A is symmetric.

#### Examples.

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

  ⎡
  ⎢
  ⎢
  ⎣

  1 | −1 | 2
  −1 | 4 | 3
  2 | 3 | −5

  ⎤
  ⎥
  ⎥
  ⎦

- Input:
  inertia(A)
- Output:

  ⎡ ⎣ | 2,1,0 | ⎤ ⎦

- Input:
  inertia(A,[[1,2,3],[4,5,6]])
- Output:

  ⎡
  ⎣

  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.
  Input:
  inertia(A,[[1,2,3],[4,5,6]],1)
- Output:

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