[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This chapter documents the linear algebra functions of Octave. Reference material for many of these options may be found in Golub and Van Loan, Matrix Computations, 2nd Ed., Johns Hopkins, 1989, and in LAPACK Users’ Guide, SIAM, 1992.
1.1 Basic Matrix Functions | ||
1.2 Matrix Factorizations | ||
1.3 Functions of a Matrix |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
balance
aa = balance (a, opt) [dd, aa] = balance(a, opt) [dd, aa] = balance (a, opt) [cc, dd, aa, bb] = balance (a, b, opt)
[dd, aa] = balance (a)
returns aa = dd \ a * dd
.
aa
is a matrix whose row/column norms are roughly equal in
magnitude, and dd
= p * d
, where p
is a permutation
matrix and d
is a diagonal matrix of powers of two. This allows
the equilibration to be computed without roundoff. Results of
eigenvalue calculation are typically improved by balancing first.
[cc, dd, aa, bb] = balance (a, b)
returns aa
(bb
)
= cc*a*dd (cc*b*dd)
), where aa
and bb
have
non-zero elements of approximately the same magnitude and cc
and dd
are permuted diagonal matrices as in dd
for
the algebraic eigenvalue problem.
The eigenvalue balancing option opt
is selected as follows:
"N"
, "n"
No balancing; arguments copied, transformation(s) set to identity.
"P"
, "p"
Permute argument(s) to isolate eigenvalues where possible.
"S"
, "s"
Scale to improve accuracy of computed eigenvalues.
"B"
, "b"
Permute and scale, in that order. Rows/columns of a (and b) that are isolated by permutation are not scaled. This is the default behavior.
Algebraic eigenvalue balancing uses standard LAPACK routines.
Generalized eigenvalue problem balancing uses Ward’s algorithm (SIAM Journal on Scientific and Statistical Computing, 1981).
cond (a)
Compute the (two-norm) condition number of a matrix. cond (a)
is
defined as norm (a) * norm (inv (a))
, and is computed via a
singular value decomposition.
det (a)
Compute the determinant of a using LINPACK.
eig
= eig (a) [v, lambda] = eig (a)
The eigenvalues (and eigenvectors) of a matrix are computed in a several
step process which begins with a Hessenberg decomposition (see
hess
), followed by a Schur decomposition (see schur
), from
which the eigenvalues are apparent. The eigenvectors, when desired, are
computed by further manipulations of the Schur decomposition.
See also: hess
, schur
.
givens
[c, s] = givens (x, y) G = givens (x, y)
G = givens(x, y)
returns a
orthogonal matrix G = [c s; -s' c]
such that
G [x; y] = [*; 0]
(x, y scalars)
inv (a)
inverse (a)
Compute the inverse of the square matrix a.
norm (a, p)
Compute the p-norm of the matrix a. If the second argument is
missing, p = 2
is assumed.
If a is a matrix:
1
1-norm, the largest column sum of a.
2
Largest singular value of a.
Inf
Infinity norm, the largest row sum of a.
"fro"
Frobenius norm of a, sqrt (sum (diag (a' * a)))
.
If a is a vector or a scalar:
Inf
max (abs (a))
.
-Inf
min (abs (a))
.
p-norm of a, (sum (abs (a) .^ p)) ^ (1/p)
.
null (a, tol)
Returns an orthonormal basis of the null space of a.
The dimension of the null space is taken as the number of singular values of a not greater than tol. If the argument tol is missing, it is computed as
max (size (a)) * max (svd (a)) * eps
orth (a, tol)
Returns an orthonormal basis of the range of a.
The dimension of the range space is taken as the number of singular values of a greater than tol. If the argument tol is missing, it is computed as
max (size (a)) * max (svd (a)) * eps
pinv (X, tol)
Returns the pseudoinverse of X. Singular values less than tol are ignored.
If the second argument is omitted, it is assumed that
tol = max (size (X)) * sigma_max (X) * eps,
where sigma_max (X)
is the maximal singular value of X.
rank (a, tol)
Compute the rank of a, using the singular value decomposition. The rank is taken to be the number of singular values of a that are greater than the specified tolerance tol. If the second argument is omitted, it is taken to be
tol = max (size (a)) * sigma (1) * eps;
where eps
is machine precision and sigma
is the largest
singular value of a
.
trace (a)
Compute the trace of a, sum (diag (a))
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
chol (a)
Compute the Cholesky factor, r, of the symmetric positive definite matrix a, where
hess (a)
Compute the Hessenberg decomposition of the matrix a.
h = hess (a) [p, h] = hess (a)
The Hessenberg decomposition is usually used as the first step in an
eigenvalue computation, but has other applications as well (see Golub,
Nash, and Van Loan, IEEE Transactions on Automatic Control, 1979. The
Hessenberg decomposition is p * h * p' = a
where p
is a
square unitary matrix (p' * p = I
, using complex-conjugate
transposition) and h
is upper Hessenberg
(i >= j+1 => h (i, j) = 0
).
lu (a)
Compute the LU decomposition of a, using subroutines from
LAPACK. The result is returned in a permuted form, according to
the optional return value p. For example, given the matrix
a = [1, 2; 3, 4]
,
[l, u, p] = lu (a)
returns
l = 1.00000 0.00000 0.33333 1.00000 u = 3.00000 4.00000 0.00000 0.66667 p = 0 1 1 0
qr (a)
Compute the QR factorization of a, using standard LAPACK
subroutines. For example, given the matrix a = [1, 2; 3, 4]
,
[q, r] = qr (a)
returns
q = -0.31623 -0.94868 -0.94868 0.31623 r = -3.16228 -4.42719 0.00000 -0.63246
The qr
factorization has applications in the solution of least
squares problems
for overdetermined systems of equations (i.e.,
is a tall, thin matrix). The qr
factorization is q * r = a
where q
is an orthogonal matrix and r
is upper triangular.
The permuted qr
factorization [q, r, pi] = qr (a)
forms
the qr
factorization such that the diagonal entries of r
are decreasing in magnitude order. For example, given the matrix
a = [1, 2; 3, 4]
,
[q, r, pi] = qr(a)
returns
q = -0.44721 -0.89443 -0.89443 0.44721 r = -4.47214 -3.13050 0.00000 0.44721 p = 0 1 1 0
The permuted qr
factorization [q, r, pi] = qr (a)
factorization allows the construction of an orthogonal basis of
span (a)
.
schur
[u, s] = schur (a, opt) opt = "a", "d", or "u" s = schur (a)
The Schur decomposition is used to compute eigenvalues of a
square matrix, and has applications in the solution of algebraic
Riccati equations in control (see are
and dare
).
schur
always returns
where
is a unitary matrix
is identity)
and
is upper triangular. The eigenvalues of
are the diagonal elements of
If the matrix
is real, then the real Schur decomposition is computed, in which the
matrix
is orthogonal and
is block upper triangular
with blocks of size at most
blocks along the diagonal. The diagonal elements of
(or the eigenvalues of the
blocks, when
appropriate) are the eigenvalues of
and
The eigenvalues are optionally ordered along the diagonal according to
the value of opt
. opt = "a"
indicates that all
eigenvalues with negative real parts should be moved to the leading
block of
(used in are
), opt = "d"
indicates that all eigenvalues
with magnitude less than one should be moved to the leading block of
(used in dare
), and opt = "u"
, the default, indicates that
no ordering of eigenvalues should occur. The leading
columns of
always span the
subspace corresponding to the
leading eigenvalues of
svd (a)
Compute the singular value decomposition of a
The function svd
normally returns the vector of singular values.
If asked for three return values, it computes
For example,
svd (hilb (3))
returns
ans = 1.4083189 0.1223271 0.0026873
and
[u, s, v] = svd (hilb (3))
returns
u = -0.82704 0.54745 0.12766 -0.45986 -0.52829 -0.71375 -0.32330 -0.64901 0.68867 s = 1.40832 0.00000 0.00000 0.00000 0.12233 0.00000 0.00000 0.00000 0.00269 v = -0.82704 0.54745 0.12766 -0.45986 -0.52829 -0.71375 -0.32330 -0.64901 0.68867
If given a second argument, svd
returns an economy-sized
decomposition, eliminating the unnecessary rows or columns of u or
v.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
expm
expm (a)
Returns the exponential of a matrix, defined as the infinite Taylor series The Taylor series is not the way to compute the matrix exponential; see Moler and Van Loan, Nineteen Dubious Ways to Compute the Exponential of a Matrix, SIAM Review, 1978. This routine uses Ward’s diagonal approximation method with three step preconditioning (SIAM Journal on Numerical Analysis, 1977).
Diagonal approximations are rational polynomials of matrices whose Taylor series matches the first terms of the Taylor series above; direct evaluation of the Taylor series (with the same preconditioning steps) may be desirable in lieu of the approximation when is ill-conditioned.
logm (a)
Compute the matrix logarithm of the square matrix a. Note that this is currently implemented in terms of an eigenvalue expansion and needs to be improved to be more robust.
sqrtm (a)
Compute the matrix square root of the square matrix a. Note that this is currently implemented in terms of an eigenvalue expansion and needs to be improved to be more robust.
kron (a, b)
Form the kronecker product of two matrices, defined block by block as
x = [a(i, j) b]
qzhess (a, b)
Compute the Hessenberg-triangular decomposition of the matrix pencil
(a, b)
. This function returns aa = q * a * z
,
bb = q * b * z
, q
, z
orthogonal. For example,
[aa, bb, q, z] = qzhess (a, b)
The Hessenberg-triangular decomposition is the first step in Moler and Stewart’s QZ decomposition algorithm. (The QZ decomposition will be included in a later release of Octave.)
Algorithm taken from Golub and Van Loan, Matrix Computations, 2nd edition.
qzval (a, b)
Compute generalized eigenvalues.
syl (a, b, c)
Solve the Sylvester equation using standard LAPACK subroutines.
[Top] | [Contents] | [Index] | [ ? ] |
This document was generated on January 15, 2023 using texi2html 5.0.
The buttons in the navigation panels have the following meaning:
Button | Name | Go to | From 1.2.3 go to |
---|---|---|---|
[ << ] | FastBack | Beginning of this chapter or previous chapter | 1 |
[ < ] | Back | Previous section in reading order | 1.2.2 |
[ Up ] | Up | Up section | 1.2 |
[ > ] | Forward | Next section in reading order | 1.2.4 |
[ >> ] | FastForward | Next chapter | 2 |
[Top] | Top | Cover (top) of document | |
[Contents] | Contents | Table of contents | |
[Index] | Index | Index | |
[ ? ] | About | About (help) |
where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:
This document was generated on January 15, 2023 using texi2html 5.0.