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
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
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
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
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
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 matrix is known for being regular but severely ill-conditioned. For example:
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: