Previous Up Next

14.2.2  Special matrices

Identity matrix.

The idn or identity command creates identity matrices.

Examples

idn(3)
     



100
010
001



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


10
01


          
Zero matrix.

The newMat command creates a matrix of all zeros.

Example

newMat(4,4)
     




0000
0000
0000
0000




          
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.

Examples

diag([1,4])
     


10
04


          
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.

Example

JordanBlock(7,3)
     



710
071
007



          
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.

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.

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])
     



1aa2
124
139



          

Previous Up Next