Special matrices

### 14.2.2 Special matrices

##### Identity matrix.

The idn or identity command creates identity matrices.

- idn takes n, a positive integer or
  A, a square matrix.
- idn(n) returns the n× n identity matrix.
- idn(A) returns the identity matrix the same size as A.

#### Examples

idn(3)

⎡ ⎢ ⎢ ⎣ |
1 | 0 | 0
0 | 1 | 0
0 | 0 | 1
| ⎤ ⎥ ⎥ ⎦

idn([[2,3],[4,5]]

⎡ ⎢ ⎣ |
1 | 0
0 | 1
| ⎤ ⎥ ⎦

##### Zero matrix.

The newMat command creates a matrix of all zeros.

- newMat takes two arguments: n and p, two positive integers. newMat(n,p) returns the n× p zero matrix.

#### Example

newMat(4,4)

⎡ ⎢ ⎢ ⎢ ⎣ |
0 | 0 | 0 | 0
0 | 0 | 0 | 0
0 | 0 | 0 | 0
0 | 0 | 0 | 0
| ⎤ ⎥ ⎥ ⎥ ⎦

##### Diagonals of matrices and diagonal matrices.

The diag or BlockDiagonal command either creates a diagonal matrix or finds the diagonal elements of an existing matrix or creates diagonal matrices.

- diag takes L, a list or a square matrix.
- diag(L) (for a list L) returns the diagonal matrix with the entries of L on the diagonal.
- diag(L) (for a matrix L) returns a list consisting of the diagonal elements of L.

#### Examples

diag([1,4])

⎡ ⎢ ⎣ |
1 | 0
0 | 4
| ⎤ ⎥ ⎦

diag([[1,2],[3,4]])

| ⎡ ⎣ | 1,4 | ⎤ ⎦

##### Jordan blocks.

The JordanBlock command creates a Jordan block, i.e. a square matrix with the same value for all diagonal elements, ones just above the diagonal, and zeros everywhere else.

- JordanBlock takes two arguments:
  - a, an expression.
  - n, a positive integer.
  JordanBlock(a,n) returns the n× n matrix with as on the principal diagonal, ones above this diagonal and zeros everywhere else.

#### Example

JordanBlock(7,3)

⎡ ⎢ ⎢ ⎣ |
7 | 1 | 0
0 | 7 | 1
0 | 0 | 7
| ⎤ ⎥ ⎥ ⎦

##### Hilbert matrix.

A Hilbert matrix is a square matrix whose element in the ith row and jth column (recall that the indices are zero-based) is

aj,k= |
1
j+k+1
| .

The hilbert command creates Hilbert matrices. See Section 21.4.6 for other uses of hilbert.

- hilbert takes n, a positive integer.
- hilbert(n) returns the n× n Hilbert matrix.

#### Examples

hilbert(4)

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

Hilbert matrix is known for being regular but severely ill-conditioned. For example:

cond(hilbert(10))

3.53654789112×1013 |  |  |  |  |  |  |  |  |  |

##### Vandermonde matrix.

A Vandermonde matrix is a square matrix where each row starts with a 1 and is in geometric progression. The vandermonde command finds a Vandermonde matrix.

- vandermonde takes X=[x0,…,xn−1], a vector.
- vandermonde(X) returns the corresponding Vandermonde matrix; namely, the kth row of the matrix is the vector whose components are xik for i=0,…,n−1 and k=0,…,n−1.

##### Remark.

Remember that the indices of the rows and columns begin at 0 with Xcas.

#### Example

If a is symbolic else enter purge(a) before:

vandermonde([a,2,3])

⎡ ⎢ ⎢ ⎣ |
1 | a | a2
1 | 2 | 4
1 | 3 | 9
| ⎤ ⎥ ⎥ ⎦