This chapter documents the linear algebra functions of Octave. Reference material for many of these functions may be found in Golub and Van Loan, Matrix Computations, 2nd Ed., Johns Hopkins, 1989, and in LAPACK Users' Guide, SIAM, 1992.
[dd, aa] = balance (a)
returns aa = dd \ a * dd
.
aa
is a matrix whose row and 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 = cc*a*dd
and
bb = 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"
"P"
, "p"
"S"
, "s"
"B"
, "b"
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)
is
defined as norm (a) * norm (inv (a))
, and is computed via a
singular value decomposition.
For example,
givens (1, 1) => 0.70711 0.70711 -0.70711 0.70711
p = 2
is assumed.
If a is a matrix:
1
2
Inf
"fro"
sqrt (sum (diag (a' * a)))
.
If a is a vector or a scalar:
Inf
max (abs (a))
.
-Inf
min (abs (a))
.
(sum (abs (a) .^ p)) ^ (1/p)
.
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
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
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.
tol = max (size (a)) * sigma (1) * eps;
where eps
is machine precision and sigma
is the largest
singular value of a.
sum (diag (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
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
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
The permuted QR factorization [q, r, p] =
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, p] = qr (a)
factorization allows the construction of an orthogonal basis of
span (a)
.
are
and dare
).
schur
always returns
where
is a unitary matrix
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
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.
x = [a(i, j) b]
For example,
kron (1:4, ones (3, 1)) => 1 2 3 4 1 2 3 4 1 2 3 4
(a, b)
, returning
aa = q * a * z
,
bb = q * b * z
, with q and z
orthogonal. For example,
[aa, bb, q, z] = qzhess ([1, 2; 3, 4], [5, 6; 7, 8]) => aa = [ -3.02244, -4.41741; 0.92998, 0.69749 ] => bb = [ -8.60233, -9.99730; 0.00000, -0.23250 ] => q = [ -0.58124, -0.81373; -0.81373, 0.58124 ] => z = [ 1, 0; 0, 1 ]
The Hessenberg-triangular decomposition is the first step in Moler and Stewart's QZ decomposition algorithm.
Algorithm taken from Golub and Van Loan, Matrix Computations, 2nd edition.
The arguments a and b must be real matrices.
syl ([1, 2; 3, 4], [5, 6; 7, 8], [9, 10; 11, 12]) => [ -0.50000, -0.66667; -0.66667, -0.50000 ]
Go to the first, previous, next, last section, table of contents.