6.44.2 Special matrices
Identity matrix: idn identity
The idn command finds identity matrices.
-
idn takes one argument:
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.
-
Input:
idn(3)
Output:
- Input:
idn([[2,3],[4,5]]
Output:
Zero matrix: newMat
The newMat command creates a matrix of all 0s.
-
newMat takes two arguments:
n and p, two positive integers.
newMat(n,p) returns the n× p zero matrix.
Example.
Input:
newMat(4,4)
Output:
Diagonals of matrices and diagonal matrices: BlockDiagonal diag
The diag command either creates a diagonal matrix or finds
the diagonal elements of an existing matrix.
BlockDiagonal is a synonym for diag.
-
diag takes one argument:
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.
-
Input:
diag([1,4])
Output:
- Input:
diag([[1,2],[3,4]])
Output:
Jordan block: JordanBlock
The JordanBlock command creates a Jordan Block; i.e., a
square matrix with the same value for all diagonal elements, 1s just
above the diagonal, and 0s everyone 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, 1s above this diagonal and 0s
everywhere else.
Example.
Input:
JordanBlock(7,3)
Output:
Hilbert matrix: hilbert
A Hilbert matrix is a square matrix whose element in the ith row and
jth column (recall the numbering starting at 0) is
The hilbert command finds Hilbert matrices.
-
hilbert takes one argument:
n, a positive integer.
- hilbert(n) returns the n× n Hilbert matrix.
Example.
Input:
hilbert(4)
Output:
⎛
⎜
⎜
⎜
⎜
⎜
⎜
⎜
⎜
⎜
⎜
⎜
⎜
⎜
⎜
⎜
⎝ | | ⎞
⎟
⎟
⎟
⎟
⎟
⎟
⎟
⎟
⎟
⎟
⎟
⎟
⎟
⎟
⎟
⎠ |
|
Vandermonde matrix: vandermonde
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 one argument:
X=[x0,…,xn−1], a vector.
- vandermonde(X) returns the corresponding
Vandermonde matrix; namely, the k-th row of the
matrix is the vector whose components are xik for i=0..n−1 and
k=0..n−1.
Warning!
The indices of the rows and columns begin at 0 with Xcas.
Example.
Input:
vandermonde([a,2,3])
Output (if a is symbolic else purge(a)):