Title: | Collection of Functions for Matrix Calculations |
---|---|
Description: | A collection of functions to support matrix calculations for probability, econometric and numerical analysis. There are additional functions that are comparable to APL functions which are useful for actuarial models such as pension mathematics. This package is used for teaching and research purposes at the Department of Finance and Risk Engineering, New York University, Polytechnic Institute, Brooklyn, NY 11201. Horn, R.A. (1990) Matrix Analysis. ISBN 978-0521386326. Lancaster, P. (1969) Theory of Matrices. ISBN 978-0124355507. Lay, D.C. (1995) Linear Algebra: And Its Applications. ISBN 978-0201845563. |
Authors: | Frederick Novomestky <[email protected]> |
Maintainer: | S. Thomas Kelly <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0-5 |
Built: | 2025-02-08 05:07:09 UTC |
Source: | https://github.com/tomkellygenetics/matrixcalc |
This function computes the direct sum of two arrays. The arrays can be numerical vectors or matrices. The result ia the block diagonal matrix.
x%s%y
x%s%y
x |
a numeric matrix or vector |
y |
a numeric matrix or vector |
If either or y is a vector, it is converted to a matrix. The result
is a block diagonal matrix
\left[ {\begin{array}{*{20}c}
{\bf{x}} & {\bf{0}} \\
{\bf{0}} & {\bf{y}} \\
\end{array}} \right]
.
A numeric matrix.
Frederick Novomestky [email protected], Kurt Hornik [email protected]
Magnus, J. R. and H. Neudecker (1999) Matrix Differential Calculus with Applications in Statistics and Econometrics, Second Edition, John Wiley.
x <- matrix( seq( 1, 4 ) ) y <- matrix( seq( 5, 8 ) ) print( x %s% y )
x <- matrix( seq( 1, 4 ) ) y <- matrix( seq( 5, 8 ) ) print( x %s% y )
This function returns a square matrix of order p = r * c that, for an r by c matrix A, transforms vec(A) to vec(A') where prime denotes transpose.
commutation.matrix(r, c=r)
commutation.matrix(r, c=r)
r |
a positive integer integer row dimension |
c |
a positive integer integer column dimension |
This function is a wrapper function that uses the function K.matrix
to do the actual work.
The matrices
constructed
by the function
H.matrices
are combined using direct product
to generate the commutation product with the following formula
An order matrix.
If either argument is less than 2, then the function stops and displays an appropriate error mesage. If either argument is not an integer, then the function stops and displays an appropriate error mesage
Frederick Novomestky [email protected]
Magnus, J. R. and H. Neudecker (1979). The commutation matrix: some properties and applications, The Annals of Statistics, 7(2), 381-394.
Magnus, J. R. and H. Neudecker (1999) Matrix Differential Calculus with Applications in Statistics and Econometrics, Second Edition, John Wiley.
K <- commutation.matrix( 3, 4 ) A <- matrix( seq( 1, 12, 1 ), nrow=3, byrow=TRUE ) vecA <- vec( A ) vecAt <- vec( t( A ) ) print( K %*% vecA ) print( vecAt )
K <- commutation.matrix( 3, 4 ) A <- matrix( seq( 1, 12, 1 ), nrow=3, byrow=TRUE ) vecA <- vec( A ) vecAt <- vec( t( A ) ) print( K %*% vecA ) print( vecAt )
This function returns the order n creation matrix, a square matrix with the sequence 1, 2, ..., n - 1 on the sub-diagonal below the principal diagonal.
creation.matrix(n)
creation.matrix(n)
n |
a positive integer greater than 1 |
The order creation matrix is also called the derivation matrix and is
used in numerical mathematics and physics. It arises in the solution of linear
dynamical systems. The form of the matrix is
\left[ {\begin{array}{*{20}{c}}
0&0&0& \cdots &0&0\\
1&0&0& \cdots &0&0\\
0&2&0& \cdots &0&0\\
0&0&3& \ddots &0&0\\
\vdots & \vdots & \vdots & \ddots & \ddots &{}\\
0&0&0& \cdots &{n - 1}&0
\end{array}} \right]
.
An order matrix.
If the argument n is not an integer that is greater than 1, the function presents an error message and stops.
Frederick Novomestky [email protected]
Aceto, L. and D. Trigiante (2001). Matrices of Pascal and Other Greats, American Mathematical Monthly, March 2001, 108(3), 232-245.
Weinberg, S. (1995). The Quantum Theory of Fields, Cambridge University Press.
H <- creation.matrix( 10 ) print( H )
H <- creation.matrix( 10 ) print( H )
This function constructs the linear transformation D that maps vech(A) to vec(A) when A is a symmetric matrix
D.matrix(n)
D.matrix(n)
n |
a positive integer value for the order of the underlying matrix |
Let be an
matrix with 1 in its
element
.
and zeroes elsewhere. These matrices are constructed by the function
T.matrices
. The formula for the
transpose of matrix is
where
is the column vector in the order
identity
matrix for column
. The function
u.vectors
generates these vectors.
It returns an matrix.
Frederick Novomestky [email protected]
Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, SIAM Journal on Algebraic Discrete Methods, 1(4), December 1980, 422-449.
Magnus, J. R. and H. Neudecker (1999). Matrix Differential Calculus with Applications in Statistics and Econometrics, Second Edition, John Wiley.
D <- D.matrix( 3 ) A <- matrix( c( 1, 2, 3, 2, 3, 4, 3, 4, 5), nrow=3, byrow=TRUE ) vecA <- vec( A ) vechA<- vech( A ) y <- D %*% vechA print( y ) print( vecA )
D <- D.matrix( 3 ) A <- matrix( c( 1, 2, 3, 2, 3, 4, 3, 4, 5), nrow=3, byrow=TRUE ) vecA <- vec( A ) vechA<- vech( A ) y <- D %*% vechA print( y ) print( vecA )
This function computes the direct product of two arrays. The arrays can be numerical vectors or matrices. The result is a matrix.
direct.prod( x, y )
direct.prod( x, y )
x |
a numeric matrix or vector |
y |
a numeric matrix or vector |
If either or
is a vector, it is converted to a matrix.
Suppose that
is an
matrix and
is an
matrix. Then, the function returns the matrix
\left[ {\begin{array}{*{20}{c}}
{{x_{1,1}}\;{\bf{y}}}&{{x_{1,2}}\;{\bf{y}}}& \cdots &{{x_{1,n}}\;{\bf{y}}}\\
{{x_{2,1}}\;{\bf{y}}}&{{x_{2,2}}\;{\bf{y}}}& \cdots &{{x_{2,n}}\;{\bf{y}}}\\
\cdots & \cdots & \cdots & \cdots \\
{{x_{m,1}}\;{\bf{y}}}&{{x_{m,2}}\;{\bf{y}}}& \cdots &{{x_{m,n}}\;{\bf{y}}}
\end{array}} \right]
.
A numeric matrix.
Frederick Novomestky [email protected], Kurt Hornik [email protected]
Magnus, J. R. and H. Neudecker (1999) Matrix Differential Calculus with Applications in Statistics and Econometrics, Second Edition, John Wiley.
x <- matrix( seq( 1, 4 ) ) y <- matrix( seq( 5, 8 ) ) print( direct.prod( x, y ) )
x <- matrix( seq( 1, 4 ) ) y <- matrix( seq( 5, 8 ) ) print( direct.prod( x, y ) )
This function computes the direct sum of two arrays. The arrays can be numerical vectors or matrices. The result ia the block diagonal matrix.
direct.sum( x, y )
direct.sum( x, y )
x |
a numeric matrix or vector |
y |
a numeric matrix or vector |
If either or y is a vector, it is converted to a matrix. The result
is a block diagonal matrix
\left[ {\begin{array}{*{20}c}
{\bf{x}} & {\bf{0}} \\
{\bf{0}} & {\bf{y}} \\
\end{array}} \right]
.
A numeric matrix.
Frederick Novomestky [email protected], Kurt Hornik [email protected]
Magnus, J. R. and H. Neudecker (1999) Matrix Differential Calculus with Applications in Statistics and Econometrics, Second Edition, John Wiley.
x <- matrix( seq( 1, 4 ) ) y <- matrix( seq( 5, 8 ) ) print( direct.sum( x, y ) )
x <- matrix( seq( 1, 4 ) ) y <- matrix( seq( 5, 8 ) ) print( direct.sum( x, y ) )
This function returns a matrix with n * n rows and n * ( n + 1 ) / 2 columns that transforms vech(A) to vec(A) where A is a symmetric n by n matrix.
duplication.matrix(n=1)
duplication.matrix(n=1)
n |
Row and column dimension |
This function is a wrapper function for the function D.matrix
.
Let be an
matrix with 1 in its
element
.
and zeroes elsewhere. These matrices are constructed by the function
T.matrices
. The formula for the
transpose of matrix is
where
is the column vector in the order
identity
matrix for column
. The function
u.vectors
generates these vectors.
It returns an matrix.
Frederick Novomestky [email protected], Kurt Hornik [email protected]
Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, SIAM Journal on Algebraic Discrete Methods, 1(4), December 1980, 422-449.
Magnus, J. R. and H. Neudecker (1999) Matrix Differential Calculus with Applications in Statistics and Econometrics, Second Edition, John Wiley.
D <- duplication.matrix( 3 ) A <- matrix( c( 1, 2, 3, 2, 3, 4, 3, 4, 5), nrow=3, byrow=TRUE ) vecA <- vec( A ) vechA<- vech( A ) y <- D %*% vechA print( y ) print( vecA )
D <- duplication.matrix( 3 ) A <- matrix( c( 1, 2, 3, 2, 3, 4, 3, 4, 5), nrow=3, byrow=TRUE ) vecA <- vec( A ) vechA<- vech( A ) y <- D %*% vechA print( y ) print( vecA )
This function constructs and returns a list of lists. The component of each sublist is a square matrix derived from the column vectors of an order n identity matrix.
E.matrices(n)
E.matrices(n)
n |
a positive integer for the order of the identity matrix |
Let {{\bf{I}}_n} = \left[ {\begin{array}{*{20}{c}}
{{{\bf{e}}_1}}&{{{\bf{e}}_2}}& \cdots &{{{\bf{e}}_n}}
\end{array}} \right]
be the order identity matrix
with corresponding unit vectors
with one in
its
th position and zeros elsewhere.
The
matrix
is computed
from the unit vectors
and
as
. These matrices
are stored as components in a list of lists.
A list with components
1 |
A sublist of |
2 |
A sublist of |
...
n |
A sublist of |
Each component of sublist
is a matrix
The argument n must be an integer value greater than or equal to 2.
Frederick Novomestky [email protected]
Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, SIAM Journal on Algebraic Discrete Methods, 1(4), December 1980, 422-449.
Magnus, J. R. and H. Neudecker (1999). Matrix Differential Calculus with Applications in Statistics and Econometrics, Second Edition, John Wiley.
E <- E.matrices( 3 )
E <- E.matrices( 3 )
This function returns a matrix with n * ( n + 1 ) / 2 rows and N * n columns which for any lower triangular matrix A transforms vec( A ) into vech(A)
elimination.matrix(n)
elimination.matrix(n)
n |
row or column dimension |
This function is a wrapper function to the function L.matrix
.
The formula used to compute the L matrix which is also called the elimination matrix is
are the order
vectors constructed by the function
u.vectors
.
are the
matrices constructed by the function
E.matrices
.
An matrix.
If the argument is not an integer, the function displays an error message and stops. If the argument is less than two, the function displays an error message and stops.
Frederick Novomestky [email protected]
Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, SIAM Journal on Algebraic Discrete Methods, 1(4), December 1980, 422-449.
Magnus, J. R. and H. Neudecker (1999) Matrix Differential Calculus with Applications in Statistics and Econometrics, Second Edition, John Wiley.
E.matrices
,
L.matrix
,
u.vectors
L <- elimination.matrix( 4 ) A <- lower.triangle( matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) ) vecA <- vec( A ) vechA <- vech( A ) y <- L %*% vecA print( y ) print( vechA )
L <- elimination.matrix( 4 ) A <- lower.triangle( matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) ) vecA <- vec( A ) vechA <- vech( A ) y <- L %*% vecA print( y ) print( vechA )
This function returns the norm of the matrix
.
entrywise.norm(x,p)
entrywise.norm(x,p)
x |
a numeric vector or matrix |
p |
a real value for the power |
Let be an
numeric matrix.
The formula used to compute the norm is
\left\| {\bf{x}} \right\|_p = \left( {\sum\limits_{i = 1}^m {\sum\limits_{j = 1}^n {\left| {x_{i,j} } \right|^p } } } \right)^{{1 \mathord{\left/
{\vphantom {1 p}} \right.
\kern-\nulldelimiterspace} p}}
.
A numeric value.
If argument x is not numeric, the function displays an error message and terminates. If argument x is neither a matrix nor a vector, the function displays an error message and terminates. If argument p is zero, the function displays an error message and terminates.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
Golub, G. H. and C. F. Van Loan (1996). Matrix Computations, Third Edition, The John Hopkins University Press.
Horn, R. A. and C. R. Johnson (1985). Matrix Analysis, Cambridge University Press.
A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) print( entrywise.norm( A, 2 ) )
A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) print( entrywise.norm( A, 2 ) )
This function constructs the order n + 1 square Fibonacci matrix which is derived from a Fibonacci sequence.
fibonacci.matrix(n)
fibonacci.matrix(n)
n |
a positive integer value |
Let be the
set of
Fibonacci numbers where
and
. The
order
Fibonacci matrix
has as typical element
{F_{i,j}} = \left\{ {\begin{array}{*{20}{c}}
{{f_{i - j + 1}}}&{i - j + 1 \ge 0}\\
0&{i - j + 1 < 0}
\end{array}} \right.
.
An order matrix
If the argument n is not a positive integer, the function presents an error message and stops.
Frederick Novomestky [email protected]
Zhang, Z. and J. Wang (2006). Bernoulli matrix and its algebraic properties, Discrete Applied Nathematics, 154, 1622-1632.
F <- fibonacci.matrix( 10 ) print( F )
F <- fibonacci.matrix( 10 ) print( F )
This function returns an order n Frobenius matrix that is useful in numerical mathematics.
frobenius.matrix(n)
frobenius.matrix(n)
n |
a positive integer value greater than 1 |
The Frobenius matrix is also called the companion matrix. It arises
in the solution of systems of linear first order differential equations.
The formula for the order Frobenius matrix is
{\bf{F}} =
\left[ {\begin{array}{*{20}{c}}0&0& \cdots &0&{{{\left( { - 1} \right)}^{n - 1}}
\left( {\begin{array}{*{20}{c}}n\\0\end{array}} \right)}\\1&0& \cdots &0&{{{\left( { - 1} \right)}^{n - 2}}
\left( {\begin{array}{*{20}{c}}n\\1\end{array}} \right)}\\0&1& \ddots &0&{{{\left( { - 1} \right)}^{n - 3}}
\left( {\begin{array}{*{20}{c}}n\\2\end{array}} \right)}\\ \vdots & \vdots & \ddots & \vdots & \vdots \\0&0& \cdots &1&{{{\left( { - 1} \right)}^0}
\left( {\begin{array}{*{20}{c}}n\\{n - 1}\end{array}}
\right)}\end{array}}
\right]
.
An order matrix
If the argument n is not a positive integer that is greater than 1, the function presents an error message and stops.
Frederick Novomestky [email protected]
Aceto, L. and D. Trigiante (2001). Matrices of Pascal and Other Greats, American Mathematical Monthly, March 2001, 108(3), 232-245.
F <- frobenius.matrix( 10 ) print( F )
F <- frobenius.matrix( 10 ) print( F )
This function returns the Frobenius norm of the matrix .
frobenius.norm(x)
frobenius.norm(x)
x |
a numeric vector or matrix |
The formula used to compute the norm is .
Note that this is the entrywise norm with exponent 2.
A numeric value.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
Golub, G. H. and C. F. Van Loan (1996). Matrix Computations, Third Edition, The John Hopkins University Press.
Horn, R. A. and C. R. Johnson (1985). Matrix Analysis, Cambridge University Press.
A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) print( frobenius.norm( A ) )
A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) print( frobenius.norm( A ) )
This function returns the Fronbenius inner product of two matrices, x and y, with the same row and column dimensions.
frobenius.prod(x, y)
frobenius.prod(x, y)
x |
a numeric matrix or vector object |
y |
a numeric matrix or vector object |
The Frobenius inner product is the element-by-element sum of
the Hadamard or Shur product of two numeric matrices. Let and
be two
matrices. Then Frobenious inner product
is computed as
.
A numeric value.
The function converts vectors to matrices if necessary. The function stops running if x or y is not numeric and an error message is displayed. The function also stops running if x and y do not have the same row and column dimensions and an error mesage is displayed.
Frederick Novomestky [email protected]
Styan, G. P. H. (1973). Hadamard Products and Multivariate Statistical Analysis, Linear Algebra and Its Applications, Elsevier, 6, 217-240.
x <- matrix( c( 1, 2, 3, 4 ), nrow=2, byrow=TRUE ) y <- matrix( c( 2, 4, 6, 8 ), nrow=2, byrow=TRUE ) z <- frobenius.prod( x, y ) print( z )
x <- matrix( c( 1, 2, 3, 4 ), nrow=2, byrow=TRUE ) y <- matrix( c( 2, 4, 6, 8 ), nrow=2, byrow=TRUE ) z <- frobenius.prod( x, y ) print( z )
This function constructs and returns a list of lists. The component of each sublist is derived from column vectors in an order r and order c identity matrix.
H.matrices(r, c = r)
H.matrices(r, c = r)
r |
a positive integer value for an order r identity matrix |
c |
a positive integer value for an order c identify matrix |
Let {{\bf{I}}_r} = \left[ {\begin{array}{*{20}{c}}
{{{\bf{a}}_1}}&{{{\bf{a}}_2}}& \cdots &{{{\bf{a}}_r}}
\end{array}} \right]
be the order identity matrix
with corresponding unit vectors
with one in
its
th position and zeros elsewhere.
Let
{{\bf{I}}_c} = \left[ {\begin{array}{*{20}{c}}
{{{\bf{b}}_1}}&{{{\bf{b}}_2}}& \cdots &{{{\bf{b}}_c}}
\end{array}} \right]
be the order identity matrix
with corresponding unit vectors
with one in
its
th position and zeros elsewhere.
The
matrix
is used in the computation of the commutation matrix.
A list with components
1 |
A sublist of |
2 |
A sublist of |
...
r |
A sublist of c components |
Each component of sublist
is a matrix
The argument n must be an integer value greater than or equal to two.
Frederick Novomestky [email protected]
Magnus, J. R. and H. Neudecker (1979). The commutation matrix: some properties and applications, The Annals of Statistics, 7(2), 381-394.
Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, SIAM Journal on Algebraic Discrete Methods, 1(4), December 1980, 422-449.
H.2.3 <- H.matrices( 2, 3 ) H.3 <- H.matrices( 3 )
H.2.3 <- H.matrices( 2, 3 ) H.3 <- H.matrices( 3 )
This function returns the Hadamard or Shur product of two matrices, x and y, that have the same row and column dimensions.
hadamard.prod(x, y)
hadamard.prod(x, y)
x |
a numeric matrix or vector object |
y |
a numeric matrix or vector object |
The Hadamard product is an element-by-element product of the two matrices. Let
and
be two
numeric matrices. The Hadamard product is
{\bf{x}}\, \circ \,{\bf{y}} = \left[ {\begin{array}{*{20}{c}}
{{x_{1,1}}\,{y_{1,1}}}&{{x_{1,2}}\,{y_{1,2}}}& \cdots &{{x_{1,n}}\,{y_{1,n}}}\\
{{x_{2,1}}\,{y_{121}}}&{{x_{2,2}}\,{y_{2,2}}}& \cdots &{{x_{2,n}}\,{y_{2,n}}}\\
\cdots & \cdots & \cdots & \cdots \\
{{x_{m,1}}\,{y_{m,1}}}&{{x_{m,2}}\,{y_{m,2}}}& \cdots &{{x_{m,n}}\,{y_{m,n}}}
\end{array}} \right]
.
It uses the * operation in R.
A matrix.
The function converts vectors to matrices if necessary. The function stops running if x or y is not numeric and an error message is displayed. The function also stops running if x and y do not have the same row and column dimensions and an error mesage is displayed.
Frederick Novomestky [email protected]
Hadamard, J (1983). Resolution d'une question relative aux determinants, Bulletin des Sciences Mathematiques, 17, 240-246.
Styan, G. P. H. (1973). Hadamard Products and Multivariate Statistical Analysis, Linear Algebra and Its Applications, Elsevier, 6, 217-240.
x <- matrix( c( 1, 2, 3, 4 ), nrow=2, byrow=TRUE ) y <- matrix( c( 2, 4, 6, 8 ), nrow=2, byrow=TRUE ) z <- hadamard.prod( x, y ) print( z )
x <- matrix( c( 1, 2, 3, 4 ), nrow=2, byrow=TRUE ) y <- matrix( c( 2, 4, 6, 8 ), nrow=2, byrow=TRUE ) z <- hadamard.prod( x, y ) print( z )
This function constructs an order n Hankel matrix from the values in the order n vector x. Each row of the matrix is a circular shift of the values in the previous row.
hankel.matrix(n, x)
hankel.matrix(n, x)
n |
a positive integer value for order of matrix greater than 1 |
x |
a vector of values used to construct the matrix |
A Hankel matrix is a square matrix with constant skew diagonals. The determinant of a Hankel matrix is called a catalecticant. Hankel matrices are formed when the hidden Mark model is sought from a given sequence of data.
An order matrix.
If the argument n is not a positive integer, the function presents an error message and stops. If the length of x is less than n, the function presents an error message and stops.
Frederick Novomestky [email protected]
Power, S. C. (1982). Hankel Operators on Hilbert Spaces, Research notes in mathematics, Series 64, Pitman Publishing.
H <- hankel.matrix( 4, seq( 1, 7 ) ) print( H )
H <- hankel.matrix( 4, seq( 1, 7 ) ) print( H )
This function returns an n by n Hilbert matrix.
hilbert.matrix(n)
hilbert.matrix(n)
n |
Order of the Hilbert matrix |
A Hilbert matrix is an order square matrix of unit fractions with elements
defined as
H_{i,j} = {1 \mathord{\left/
{\vphantom {1 {\left( {i + j - 1} \right)}}} \right.
\kern-\nulldelimiterspace} {\left( {i + j - 1} \right)}}
.
A matrix.
If the argument is less than or equal to zero, the function displays an error message and stops. If the argument is not an integer, the function displays an error message and stops.
Frederick Novomestky [email protected]
Hilbert, David (1894). Ein Beitrag zur Theorie des Legendre schen Polynoms, Acta Mathematica, Springer, Netherlands, 18, 155-159.
H <- hilbert.matrix( 4 ) print( H )
H <- hilbert.matrix( 4 ) print( H )
This function returns the Hilbert-Schmidt norm of the matrix .
hilbert.schmidt.norm(x)
hilbert.schmidt.norm(x)
x |
a numeric vector or matrix |
The formula used to compute the norm is .
This is merely the entrywise norm with exponent 2.
A numeric value.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
Golub, G. H. and C. F. Van Loan (1996). Matrix Computations, Third Edition, The John Hopkins University Press.
Horn, R. A. and C. R. Johnson (1985). Matrix Analysis, Cambridge University Press.
A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) print( hilbert.schmidt.norm( A ) )
A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) print( hilbert.schmidt.norm( A ) )
This function returns the norm of the matrix
.
inf.norm(x)
inf.norm(x)
x |
a numeric vector or matrix |
Let be an
numeric matrix.
The formula used to compute the norm is
.
This is merely the maximum absolute row sum of the
maxtris.
A numeric value.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
Golub, G. H. and C. F. Van Loan (1996). Matrix Computations, Third Edition, The John Hopkins University Press.
Horn, R. A. and C. R. Johnson (1985). Matrix Analysis, Cambridge University Press.
A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) print( inf.norm( A ) )
A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) print( inf.norm( A ) )
This function returns TRUE
if the given matrix argument x
is a square numeric matrix and that the off-diagonal elements are close
to zero in absolute value to within the given tolerance level. Otherwise,
a FALSE
value is returned.
is.diagonal.matrix(x, tol = 1e-08)
is.diagonal.matrix(x, tol = 1e-08)
x |
a numeric square matrix |
tol |
a numeric tolerance level usually left out |
A TRUE or FALSE value.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
Horn, R. A. and C. R. Johnson (1990). Matrix Analysis, Cambridge University Press.
A <- diag( 1, 3 ) is.diagonal.matrix( A ) B <- matrix( c( 1, 2, 3, 4 ), nrow=2, byrow=TRUE ) is.diagonal.matrix( B ) C <- matrix( c( 1, 0, 0, 0 ), nrow=2, byrow=TRUE ) is.diagonal.matrix( C )
A <- diag( 1, 3 ) is.diagonal.matrix( A ) B <- matrix( c( 1, 2, 3, 4 ), nrow=2, byrow=TRUE ) is.diagonal.matrix( B ) C <- matrix( c( 1, 0, 0, 0 ), nrow=2, byrow=TRUE ) is.diagonal.matrix( C )
This function returns a TRUE
value if the square matrix argument x
is idempotent, that is, the product of the matrix with itself is the matrix.
The equality test is performed to within the specified tolerance level. If
the matrix is not idempotent, then a FALSE
value is returned.
is.idempotent.matrix(x, tol = 1e-08)
is.idempotent.matrix(x, tol = 1e-08)
x |
a numeric square matrix |
tol |
a numeric tolerance level usually left out |
Idempotent matrices are used in econometric analysis. Consider the problem of
estimating the regression parameters of a standard linear model
using the method of least squares.
is an order
random vector of dependent variables.
is an
matrix whose columns are columns of
observations on one of the
independent variables. The first column
contains
ones.
is an order
random vector of zero
mean residual values.
is the order
vector of regression
parameters. The objective function that is minimized in the method of least squares is
.
The solution to ths quadratic programming problem is
The corresponding estimator for the residual vector is
.
and
are idempotent.
Idempotency of
enters into the estimation of the variance of the estimator.
A TRUE or FALSE value.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
Chang, A. C., (1984). Fundamental Methods of Mathematical Economics, Third edition, McGraw-Hill.
Green, W. H. (2003). Econometric Analysis, Fifth edition, Prentice-Hall.
Horn, R. A. and C. R. Johnson (1990). Matrix Analysis, Cambridge University Press.
A <- diag( 1, 3 ) is.idempotent.matrix( A ) B <- matrix( c( 1, 2, 3, 4 ), nrow=2, byrow=TRUE ) is.idempotent.matrix( B ) C <- matrix( c( 1, 0, 0, 0 ), nrow=2, byrow=TRUE ) is.idempotent.matrix( C )
A <- diag( 1, 3 ) is.idempotent.matrix( A ) B <- matrix( c( 1, 2, 3, 4 ), nrow=2, byrow=TRUE ) is.idempotent.matrix( B ) C <- matrix( c( 1, 0, 0, 0 ), nrow=2, byrow=TRUE ) is.idempotent.matrix( C )
This function returns TRUE if the argument, a square symmetric real matrix x, is indefinite. That is, the matrix has both positive and negative eigenvalues.
is.indefinite(x, tol=1e-8)
is.indefinite(x, tol=1e-8)
x |
a matrix |
tol |
a numeric tolerance level |
For an indefinite matrix, the matrix should positive and negative eigenvalues. The R function eigen
is used to compute the eigenvalues. If any of the eigenvalues is absolute value is less than the
given tolerance, that eigenvalue is replaced with zero. If the matrix has both positive and
negative eigenvalues, it is declared to be indefinite.
TRUE or FALSE.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
is.positive.definite
,
is.positive.semi.definite
,
is.negative.definite
,
is.negative.semi.definite
### ### identity matrix is always positive definite ### I <- diag( 1, 3 ) is.indefinite( I ) ### ### positive definite matrix ### eigenvalues are 3.4142136 2.0000000 0.585786 ### A <- matrix( c( 2, -1, 0, -1, 2, -1, 0, -1, 2 ), nrow=3, byrow=TRUE ) is.indefinite( A ) ### ### positive semi-defnite matrix ### eigenvalues are 4.732051 1.267949 8.881784e-16 ### B <- matrix( c( 2, -1, 2, -1, 2, -1, 2, -1, 2 ), nrow=3, byrow=TRUE ) is.indefinite( B ) ### ### negative definite matrix ### eigenvalues are -0.5857864 -2.0000000 -3.4142136 ### C <- matrix( c( -2, 1, 0, 1, -2, 1, 0, 1, -2 ), nrow=3, byrow=TRUE ) is.indefinite( C ) ### ### negative semi-definite matrix ### eigenvalues are 1.894210e-16 -1.267949 -4.732051 ### D <- matrix( c( -2, 1, -2, 1, -2, 1, -2, 1, -2 ), nrow=3, byrow=TRUE ) is.indefinite( D ) ### ### indefinite matrix ### eigenvalues are 3.828427 1.000000 -1.828427 ### E <- matrix( c( 1, 2, 0, 2, 1, 2, 0, 2, 1 ), nrow=3, byrow=TRUE ) is.indefinite( E )
### ### identity matrix is always positive definite ### I <- diag( 1, 3 ) is.indefinite( I ) ### ### positive definite matrix ### eigenvalues are 3.4142136 2.0000000 0.585786 ### A <- matrix( c( 2, -1, 0, -1, 2, -1, 0, -1, 2 ), nrow=3, byrow=TRUE ) is.indefinite( A ) ### ### positive semi-defnite matrix ### eigenvalues are 4.732051 1.267949 8.881784e-16 ### B <- matrix( c( 2, -1, 2, -1, 2, -1, 2, -1, 2 ), nrow=3, byrow=TRUE ) is.indefinite( B ) ### ### negative definite matrix ### eigenvalues are -0.5857864 -2.0000000 -3.4142136 ### C <- matrix( c( -2, 1, 0, 1, -2, 1, 0, 1, -2 ), nrow=3, byrow=TRUE ) is.indefinite( C ) ### ### negative semi-definite matrix ### eigenvalues are 1.894210e-16 -1.267949 -4.732051 ### D <- matrix( c( -2, 1, -2, 1, -2, 1, -2, 1, -2 ), nrow=3, byrow=TRUE ) is.indefinite( D ) ### ### indefinite matrix ### eigenvalues are 3.828427 1.000000 -1.828427 ### E <- matrix( c( 1, 2, 0, 2, 1, 2, 0, 2, 1 ), nrow=3, byrow=TRUE ) is.indefinite( E )
This function returns TRUE if the argument, a square symmetric real matrix x, is negative definite.
is.negative.definite(x, tol=1e-8)
is.negative.definite(x, tol=1e-8)
x |
a matrix |
tol |
a numeric tolerance level |
For a negative definite matrix, the eigenvalues should be negative. The R function eigen
is used to compute the eigenvalues. If any of the eigenvalues in absolute value is less than
the given tolerance, that eigenvalue is replaced with zero. If any of the eigenvalues is greater than or equal to zero,
then the matrix is not negative definite. Otherwise, the matrix is declared to be negative definite.
TRUE or FALSE.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
is.positive.definite
,
is.positive.semi.definite
,
is.negative.semi.definite
,
is.indefinite
### ### identity matrix is always positive definite I <- diag( 1, 3 ) is.negative.definite( I ) ### ### positive definite matrix ### eigenvalues are 3.4142136 2.0000000 0.585786 ### A <- matrix( c( 2, -1, 0, -1, 2, -1, 0, -1, 2 ), nrow=3, byrow=TRUE ) is.negative.definite( A ) ### ### positive semi-defnite matrix ### eigenvalues are 4.732051 1.267949 8.881784e-16 ### B <- matrix( c( 2, -1, 2, -1, 2, -1, 2, -1, 2 ), nrow=3, byrow=TRUE ) is.negative.definite( B ) ### ### negative definite matrix ### eigenvalues are -0.5857864 -2.0000000 -3.4142136 ### C <- matrix( c( -2, 1, 0, 1, -2, 1, 0, 1, -2 ), nrow=3, byrow=TRUE ) is.negative.definite( C ) ### ### negative semi-definite matrix ### eigenvalues are 1.894210e-16 -1.267949 -4.732051 ### D <- matrix( c( -2, 1, -2, 1, -2, 1, -2, 1, -2 ), nrow=3, byrow=TRUE ) is.negative.definite( D ) ### ### indefinite matrix ### eigenvalues are 3.828427 1.000000 -1.828427 ### E <- matrix( c( 1, 2, 0, 2, 1, 2, 0, 2, 1 ), nrow=3, byrow=TRUE ) is.negative.definite( E )
### ### identity matrix is always positive definite I <- diag( 1, 3 ) is.negative.definite( I ) ### ### positive definite matrix ### eigenvalues are 3.4142136 2.0000000 0.585786 ### A <- matrix( c( 2, -1, 0, -1, 2, -1, 0, -1, 2 ), nrow=3, byrow=TRUE ) is.negative.definite( A ) ### ### positive semi-defnite matrix ### eigenvalues are 4.732051 1.267949 8.881784e-16 ### B <- matrix( c( 2, -1, 2, -1, 2, -1, 2, -1, 2 ), nrow=3, byrow=TRUE ) is.negative.definite( B ) ### ### negative definite matrix ### eigenvalues are -0.5857864 -2.0000000 -3.4142136 ### C <- matrix( c( -2, 1, 0, 1, -2, 1, 0, 1, -2 ), nrow=3, byrow=TRUE ) is.negative.definite( C ) ### ### negative semi-definite matrix ### eigenvalues are 1.894210e-16 -1.267949 -4.732051 ### D <- matrix( c( -2, 1, -2, 1, -2, 1, -2, 1, -2 ), nrow=3, byrow=TRUE ) is.negative.definite( D ) ### ### indefinite matrix ### eigenvalues are 3.828427 1.000000 -1.828427 ### E <- matrix( c( 1, 2, 0, 2, 1, 2, 0, 2, 1 ), nrow=3, byrow=TRUE ) is.negative.definite( E )
This function returns TRUE if the argument, a square symmetric real matrix x, is negative semi-negative.
is.negative.semi.definite(x, tol=1e-8)
is.negative.semi.definite(x, tol=1e-8)
x |
a matrix |
tol |
a numeric tolerance level |
For a negative semi-definite matrix, the eigenvalues should be non-positive.
The R function eigen
is used to compute the eigenvalues.
If any of the eigenvalues in absolute value is less than the given tolerance, that eigenvalue
is replaced with zero. Then, if any of the eigenvalues is greater than zero, the matrix
is not negative semi-definite. Otherwise, the matrix is declared to be negative semi-definite.
TRUE or FALSE.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
is.positive.definite
,
is.positive.semi.definite
,
is.negative.definite
,
is.indefinite
### ### identity matrix is always positive definite I <- diag( 1, 3 ) is.negative.semi.definite( I ) ### ### positive definite matrix ### eigenvalues are 3.4142136 2.0000000 0.585786 ### A <- matrix( c( 2, -1, 0, -1, 2, -1, 0, -1, 2 ), nrow=3, byrow=TRUE ) is.negative.semi.definite( A ) ### ### positive semi-defnite matrix ### eigenvalues are 4.732051 1.267949 8.881784e-16 ### B <- matrix( c( 2, -1, 2, -1, 2, -1, 2, -1, 2 ), nrow=3, byrow=TRUE ) is.negative.semi.definite( B ) ### ### negative definite matrix ### eigenvalues are -0.5857864 -2.0000000 -3.4142136 ### C <- matrix( c( -2, 1, 0, 1, -2, 1, 0, 1, -2 ), nrow=3, byrow=TRUE ) is.negative.semi.definite( C ) ### ### negative semi-definite matrix ### eigenvalues are 1.894210e-16 -1.267949 -4.732051 ### D <- matrix( c( -2, 1, -2, 1, -2, 1, -2, 1, -2 ), nrow=3, byrow=TRUE ) is.negative.semi.definite( D ) ### ### indefinite matrix ### eigenvalues are 3.828427 1.000000 -1.828427 ### E <- matrix( c( 1, 2, 0, 2, 1, 2, 0, 2, 1 ), nrow=3, byrow=TRUE ) is.negative.semi.definite( E )
### ### identity matrix is always positive definite I <- diag( 1, 3 ) is.negative.semi.definite( I ) ### ### positive definite matrix ### eigenvalues are 3.4142136 2.0000000 0.585786 ### A <- matrix( c( 2, -1, 0, -1, 2, -1, 0, -1, 2 ), nrow=3, byrow=TRUE ) is.negative.semi.definite( A ) ### ### positive semi-defnite matrix ### eigenvalues are 4.732051 1.267949 8.881784e-16 ### B <- matrix( c( 2, -1, 2, -1, 2, -1, 2, -1, 2 ), nrow=3, byrow=TRUE ) is.negative.semi.definite( B ) ### ### negative definite matrix ### eigenvalues are -0.5857864 -2.0000000 -3.4142136 ### C <- matrix( c( -2, 1, 0, 1, -2, 1, 0, 1, -2 ), nrow=3, byrow=TRUE ) is.negative.semi.definite( C ) ### ### negative semi-definite matrix ### eigenvalues are 1.894210e-16 -1.267949 -4.732051 ### D <- matrix( c( -2, 1, -2, 1, -2, 1, -2, 1, -2 ), nrow=3, byrow=TRUE ) is.negative.semi.definite( D ) ### ### indefinite matrix ### eigenvalues are 3.828427 1.000000 -1.828427 ### E <- matrix( c( 1, 2, 0, 2, 1, 2, 0, 2, 1 ), nrow=3, byrow=TRUE ) is.negative.semi.definite( E )
This function returns TRUE
is the matrix argument is non-singular
and FALSE
otherwise.
is.non.singular.matrix(x, tol = 1e-08)
is.non.singular.matrix(x, tol = 1e-08)
x |
a numeric square matrix |
tol |
a numeric tolerance level usually left out |
The determinant of the matrix x
is first computed.
If the absolute value of the determinant is greater than or equal to the given
tolerance level, then a TRUE
value is returned.
Otherwise, a FALSE
value is returned.
TRUE or FALSE value.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
Horn, R. A. and C. R. Johnson (1990). Matrix Analysis, Cambridge University Press.
A <- diag( 1, 3 ) is.non.singular.matrix( A ) B <- matrix( c( 0, 0, 3, 4 ), nrow=2, byrow=TRUE ) is.non.singular.matrix( B )
A <- diag( 1, 3 ) is.non.singular.matrix( A ) B <- matrix( c( 0, 0, 3, 4 ), nrow=2, byrow=TRUE ) is.non.singular.matrix( B )
This function returns TRUE if the argument, a square symmetric real matrix x, is positive definite.
is.positive.definite(x, tol=1e-8)
is.positive.definite(x, tol=1e-8)
x |
a matrix |
tol |
a numeric tolerance level |
For a positive definite matrix, the eigenvalues should be positive. The R function eigen
is used to compute the eigenvalues. If any of the eigenvalues in absolute value is less than the
given tolerance, that eigenvalue is replaced with zero. If any of the eigenvalues is less than or equal to zero,
then the matrix is not positive definite. Otherwise, the matrix is declared to be positive definite.
TRUE or FALSE.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
is.positive.semi.definite
,
is.negative.definite
,
is.negative.semi.definite
,
is.indefinite
### ### identity matrix is always positive definite I <- diag( 1, 3 ) is.positive.definite( I ) ### ### positive definite matrix ### eigenvalues are 3.4142136 2.0000000 0.585786 ### A <- matrix( c( 2, -1, 0, -1, 2, -1, 0, -1, 2 ), nrow=3, byrow=TRUE ) is.positive.definite( A ) ### ### positive semi-defnite matrix ### eigenvalues are 4.732051 1.267949 8.881784e-16 ### B <- matrix( c( 2, -1, 2, -1, 2, -1, 2, -1, 2 ), nrow=3, byrow=TRUE ) is.positive.definite( B ) ### ### negative definite matrix ### eigenvalues are -0.5857864 -2.0000000 -3.4142136 ### C <- matrix( c( -2, 1, 0, 1, -2, 1, 0, 1, -2 ), nrow=3, byrow=TRUE ) is.positive.definite( C ) ### ### negative semi-definite matrix ### eigenvalues are 1.894210e-16 -1.267949 -4.732051 ### D <- matrix( c( -2, 1, -2, 1, -2, 1, -2, 1, -2 ), nrow=3, byrow=TRUE ) is.positive.definite( D ) ### ### indefinite matrix ### eigenvalues are 3.828427 1.000000 -1.828427 ### E <- matrix( c( 1, 2, 0, 2, 1, 2, 0, 2, 1 ), nrow=3, byrow=TRUE ) is.positive.definite( E )
### ### identity matrix is always positive definite I <- diag( 1, 3 ) is.positive.definite( I ) ### ### positive definite matrix ### eigenvalues are 3.4142136 2.0000000 0.585786 ### A <- matrix( c( 2, -1, 0, -1, 2, -1, 0, -1, 2 ), nrow=3, byrow=TRUE ) is.positive.definite( A ) ### ### positive semi-defnite matrix ### eigenvalues are 4.732051 1.267949 8.881784e-16 ### B <- matrix( c( 2, -1, 2, -1, 2, -1, 2, -1, 2 ), nrow=3, byrow=TRUE ) is.positive.definite( B ) ### ### negative definite matrix ### eigenvalues are -0.5857864 -2.0000000 -3.4142136 ### C <- matrix( c( -2, 1, 0, 1, -2, 1, 0, 1, -2 ), nrow=3, byrow=TRUE ) is.positive.definite( C ) ### ### negative semi-definite matrix ### eigenvalues are 1.894210e-16 -1.267949 -4.732051 ### D <- matrix( c( -2, 1, -2, 1, -2, 1, -2, 1, -2 ), nrow=3, byrow=TRUE ) is.positive.definite( D ) ### ### indefinite matrix ### eigenvalues are 3.828427 1.000000 -1.828427 ### E <- matrix( c( 1, 2, 0, 2, 1, 2, 0, 2, 1 ), nrow=3, byrow=TRUE ) is.positive.definite( E )
This function returns TRUE if the argument, a square symmetric real matrix x, is positive semi-definite.
is.positive.semi.definite(x, tol=1e-8)
is.positive.semi.definite(x, tol=1e-8)
x |
a matrix |
tol |
a numeric tolerance level |
For a positive semi-definite matrix, the eigenvalues should be non-negative. The R function eigen
is used to compute the eigenvalues. If any of the eigenvalues is less than zero,
then the matrix is not positive semi-definite. Otherwise, the matrix is declared
to be positive semi-definite.
TRUE or FALSE.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
is.positive.definite
,
is.negative.definite
,
is.negative.semi.definite
,
is.indefinite
### ### identity matrix is always positive definite I <- diag( 1, 3 ) is.positive.semi.definite( I ) ### ### positive definite matrix ### eigenvalues are 3.4142136 2.0000000 0.585786 ### A <- matrix( c( 2, -1, 0, -1, 2, -1, 0, -1, 2 ), nrow=3, byrow=TRUE ) is.positive.semi.definite( A ) ### ### positive semi-defnite matrix ### eigenvalues are 4.732051 1.267949 8.881784e-16 ### B <- matrix( c( 2, -1, 2, -1, 2, -1, 2, -1, 2 ), nrow=3, byrow=TRUE ) is.positive.semi.definite( B ) ### ### negative definite matrix ### eigenvalues are -0.5857864 -2.0000000 -3.4142136 ### C <- matrix( c( -2, 1, 0, 1, -2, 1, 0, 1, -2 ), nrow=3, byrow=TRUE ) is.positive.semi.definite( C ) ### ### negative semi-definite matrix ### eigenvalues are 1.894210e-16 -1.267949 -4.732051 ### D <- matrix( c( -2, 1, -2, 1, -2, 1, -2, 1, -2 ), nrow=3, byrow=TRUE ) is.positive.semi.definite( D ) ### ### indefinite matrix ### eigenvalues are 3.828427 1.000000 -1.828427 ### E <- matrix( c( 1, 2, 0, 2, 1, 2, 0, 2, 1 ), nrow=3, byrow=TRUE ) is.positive.semi.definite( E )
### ### identity matrix is always positive definite I <- diag( 1, 3 ) is.positive.semi.definite( I ) ### ### positive definite matrix ### eigenvalues are 3.4142136 2.0000000 0.585786 ### A <- matrix( c( 2, -1, 0, -1, 2, -1, 0, -1, 2 ), nrow=3, byrow=TRUE ) is.positive.semi.definite( A ) ### ### positive semi-defnite matrix ### eigenvalues are 4.732051 1.267949 8.881784e-16 ### B <- matrix( c( 2, -1, 2, -1, 2, -1, 2, -1, 2 ), nrow=3, byrow=TRUE ) is.positive.semi.definite( B ) ### ### negative definite matrix ### eigenvalues are -0.5857864 -2.0000000 -3.4142136 ### C <- matrix( c( -2, 1, 0, 1, -2, 1, 0, 1, -2 ), nrow=3, byrow=TRUE ) is.positive.semi.definite( C ) ### ### negative semi-definite matrix ### eigenvalues are 1.894210e-16 -1.267949 -4.732051 ### D <- matrix( c( -2, 1, -2, 1, -2, 1, -2, 1, -2 ), nrow=3, byrow=TRUE ) is.positive.semi.definite( D ) ### ### indefinite matrix ### eigenvalues are 3.828427 1.000000 -1.828427 ### E <- matrix( c( 1, 2, 0, 2, 1, 2, 0, 2, 1 ), nrow=3, byrow=TRUE ) is.positive.semi.definite( E )
This function returns TRUE
is the matrix argument is singular
and FALSE
otherwise.
is.singular.matrix(x, tol = 1e-08)
is.singular.matrix(x, tol = 1e-08)
x |
a numeric square matrix |
tol |
a numeric tolerance level usually left out |
The determinant of the matrix x
is first computed.
If the absolute value of the determinant is less than the given
tolerance level, then a TRUE
value is returned.
Otherwise, a FALSE
value is returned.
A TRUE or FALSE value.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
Horn, R. A. and C. R. Johnson (1990). Matrix Analysis, Cambridge University Press.
A <- diag( 1, 3 ) is.singular.matrix( A ) B <- matrix( c( 0, 0, 3, 4 ), nrow=2, byrow=TRUE ) is.singular.matrix( B )
A <- diag( 1, 3 ) is.singular.matrix( A ) B <- matrix( c( 0, 0, 3, 4 ), nrow=2, byrow=TRUE ) is.singular.matrix( B )
This function returns TRUE
if the matrix argument x is
a skew symmetric matrix, i.e., the transpose of the matrix is
the negative of the matrix. Otherwise, FALSE
is returned.
is.skew.symmetric.matrix(x, tol = 1e-08)
is.skew.symmetric.matrix(x, tol = 1e-08)
x |
a numeric square matrix |
tol |
a numeric tolerance level usually left out |
Let be an order
matrix. If every element
of the matrix
in absolute value is less
than the given tolerance, then the matrix argument is declared to be
skew symmetric.
A TRUE or FALSE value.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
Horn, R. A. and C. R. Johnson (1990). Matrix Analysis, Cambridge University Press.
A <- diag( 1, 3 ) is.skew.symmetric.matrix( A ) B <- matrix( c( 0, -2, -1, -2, 0, -4, 1, 4, 0 ), nrow=3, byrow=TRUE ) is.skew.symmetric.matrix( B ) C <- matrix( c( 0, 2, 1, 2, 0, 4, 1, 4, 0 ), nrow=3, byrow=TRUE ) is.skew.symmetric.matrix( C )
A <- diag( 1, 3 ) is.skew.symmetric.matrix( A ) B <- matrix( c( 0, -2, -1, -2, 0, -4, 1, 4, 0 ), nrow=3, byrow=TRUE ) is.skew.symmetric.matrix( B ) C <- matrix( c( 0, 2, 1, 2, 0, 4, 1, 4, 0 ), nrow=3, byrow=TRUE ) is.skew.symmetric.matrix( C )
The function returns TRUE if the argument is a square matrix and FALSE otherwise.
is.square.matrix(x)
is.square.matrix(x)
x |
a matrix |
TRUE or FALSE
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
A <- matrix( seq( 1, 12, 1 ), nrow=3, byrow=TRUE ) is.square.matrix( A ) B <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) is.square.matrix( B )
A <- matrix( seq( 1, 12, 1 ), nrow=3, byrow=TRUE ) is.square.matrix( A ) B <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) is.square.matrix( B )
This function returns TRUE if the argument is a numeric symmetric square matrix and FALSE otherwise.
is.symmetric.matrix(x)
is.symmetric.matrix(x)
x |
an R object |
TRUE or FALSE.
If the argument is not a numeric matrix, the function displays an error message and stops. If the argument is not a square matrix, the function displays an error message and stops.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
A <- matrix( c( 1, 2, 3, 4 ), nrow=2, byrow=TRUE ) is.symmetric.matrix( A ) B <- matrix( c( 1, 2, 2, 1 ), nrow=2, byrow=TRUE ) is.symmetric.matrix( B )
A <- matrix( c( 1, 2, 3, 4 ), nrow=2, byrow=TRUE ) is.symmetric.matrix( A ) B <- matrix( c( 1, 2, 2, 1 ), nrow=2, byrow=TRUE ) is.symmetric.matrix( B )
This function returns a square matrix of order p = r * c that, for an r by c matrix A, transforms vec(A) to vec(A') where prime denotes transpose.
K.matrix(r, c = r)
K.matrix(r, c = r)
r |
a positive integer row dimension |
c |
a positive integer column dimension |
The matrices
constructed
by the function
H.matrices
are combined using direct product
to generate the commutation product with the formula
An order matrix.
If either argument is less than 2, then the function stops and displays an appropriate error mesage. If either argument is not an integer, then the function stops and displays an appropriate error mesage
Frederick Novomestky [email protected]
Magnus, J. R. and H. Neudecker (1979). The commutation matrix: some properties and applications, The Annals of Statistics, 7(2), 381-394.
Magnus, J. R. and H. Neudecker (1999) Matrix Differential Calculus with Applications in Statistics and Econometrics, Second Edition, John Wiley.
K <- K.matrix( 3, 4 ) A <- matrix( seq( 1, 12, 1 ), nrow=3, byrow=TRUE ) vecA <- vec( A ) vecAt <- vec( t( A ) ) y <- K %*% vecA print( y ) print( vecAt )
K <- K.matrix( 3, 4 ) A <- matrix( seq( 1, 12, 1 ), nrow=3, byrow=TRUE ) vecA <- vec( A ) vecAt <- vec( t( A ) ) y <- K %*% vecA print( y ) print( vecAt )
This function returns a matrix with n * ( n + 1 ) / 2 rows and N * n columns which for any lower triangular matrix A transforms vec( A ) into vech(A)
L.matrix(n)
L.matrix(n)
n |
a positive integer order for the associated matrix A |
The formula used to compute the L matrix which is also called the elimination matrix is
are the
vectors constructed by the function
u.vectors
.
are the
matrices constructed by the function
E.matrices
.
An matrix.
If the argument is not an integer, the function displays an error message and stops. If the argument is less than two, the function displays an error message and stops.
Frederick Novomestky [email protected]
Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, SIAM Journal on Algebraic Discrete Methods, 1(4), December 1980, 422-449.
Magnus, J. R. and H. Neudecker (1999) Matrix Differential Calculus with Applications in Statistics and Econometrics, Second Edition, John Wiley.
elimination.matrix
,
E.matrices
,
u.vectors
,
L <- L.matrix( 4 ) A <- lower.triangle( matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) ) vecA <- vec( A ) vechA <- vech( A ) y <- L %*% vecA print( y ) print( vechA )
L <- L.matrix( 4 ) A <- lower.triangle( matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) ) vecA <- vec( A ) vechA <- vech( A ) y <- L %*% vecA print( y ) print( vechA )
Returns the lower triangle including the diagonal of a square numeric matrix.
lower.triangle(x)
lower.triangle(x)
x |
a matrix |
A matrix.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
B <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) lower.triangle( B )
B <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) lower.triangle( B )
This function performs an LU decomposition of the given square matrix argument the results are returned in a list of named components. The Doolittle decomposition method is used to obtain the lower and upper triangular matrices
lu.decomposition(x)
lu.decomposition(x)
x |
a numeric square matrix |
The Doolittle decomposition without row exchanges is performed generating the lower and upper triangular matrices separately rather than in one matrix.
A list with two named components.
L |
The numeric lower triangular matrix |
U |
The number upper triangular matrix |
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
Golub, G. H. and C. F. Van Loan (1996). Matrix Computations, Third Edition, John Hopkins University Press
Horn, R. A. and C. R. Johnson (1985). Matrix Analysis, Cambridge University Press.
A <- matrix( c ( 1, 2, 2, 1 ), nrow=2, byrow=TRUE) luA <- lu.decomposition( A ) L <- luA$L U <- luA$U print( L ) print( U ) print( L %*% U ) print( A ) B <- matrix( c( 2, -1, -2, -4, 6, 3, -4, -2, 8 ), nrow=3, byrow=TRUE ) luB <- lu.decomposition( B ) L <- luB$L U <- luB$U print( L ) print( U ) print( L %*% U ) print( B )
A <- matrix( c ( 1, 2, 2, 1 ), nrow=2, byrow=TRUE) luA <- lu.decomposition( A ) L <- luA$L U <- luA$U print( L ) print( U ) print( L %*% U ) print( A ) B <- matrix( c( 2, -1, -2, -4, 6, 3, -4, -2, 8 ), nrow=3, byrow=TRUE ) luB <- lu.decomposition( B ) L <- luB$L U <- luB$U print( L ) print( U ) print( L %*% U ) print( B )
This function returns the inverse of a square matrix computed using the R function solve.
matrix.inverse(x)
matrix.inverse(x)
x |
a square numeric matrix |
A matrix.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
A <- matrix( c ( 1, 2, 2, 1 ), nrow=2, byrow=TRUE) print( A ) invA <- matrix.inverse( A ) print( invA ) print( A %*% invA ) print( invA %*% A )
A <- matrix( c ( 1, 2, 2, 1 ), nrow=2, byrow=TRUE) print( A ) invA <- matrix.inverse( A ) print( invA ) print( A %*% invA ) print( invA %*% A )
This function computes the k-th power of order n square matrix x If k is zero, the order n identity matrix is returned. argument k must be an integer.
matrix.power(x, k)
matrix.power(x, k)
x |
a numeric square matrix |
k |
a numeric exponent |
The matrix power is computed by successive matrix multiplications. If the exponent is zero, the order n identity matrix is returned. If the exponent is negative, the inverse of the matrix is raised to the given power.
An order matrix.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
A <- matrix( c ( 1, 2, 2, 1 ), nrow=2, byrow=TRUE) matrix.power( A, -2 ) matrix.power( A, -1 ) matrix.power( A, 0 ) matrix.power( A, 1 ) matrix.power( A, 2 )
A <- matrix( c ( 1, 2, 2, 1 ), nrow=2, byrow=TRUE) matrix.power( A, -2 ) matrix.power( A, -1 ) matrix.power( A, 0 ) matrix.power( A, 1 ) matrix.power( A, 2 )
This function returns the rank of a square numeric matrix based on the selected method.
matrix.rank(x, method = c("qr", "chol"))
matrix.rank(x, method = c("qr", "chol"))
x |
a matrix |
method |
a character string that specifies the method to be used |
If the user specifies "qr" as the method, then the QR decomposition function is used to obtain the rank. If the user specifies "chol" as the method, the rank is obtained from the attributes of the value returned.
An integer.
If the argument is not a square numeric matrix, then the function presents an error message and stops.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
A <- diag( seq( 1, 4, 1 ) ) matrix.rank( A ) B <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) matrix.rank( B )
A <- diag( seq( 1, 4, 1 ) ) matrix.rank( A ) B <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) matrix.rank( B )
This function returns the trace of a given square numeric matrix.
matrix.trace(x)
matrix.trace(x)
x |
a matrix |
A numeric value which is the sum of the values on the diagonal.
If the argument x is not numeric, the function presents and error message and terminates. If the argument x is not a square matrix, the function presents an error message and terminates.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
A <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) matrix.trace( A )
A <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) matrix.trace( A )
This function returns the max norm of a real matrix.
maximum.norm(x)
maximum.norm(x)
x |
a numeric matrix or vector |
Let be an
real matrix. The max norm returned
is
.
A numeric value.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
Golub, G. H. and C. F. Van Loan (1996). Matrix Computations, Third Edition, The John Hopkins University Press.
Horn, R. A. and C. R. Johnson (1985). Matrix Analysis, Cambridge University Press.
A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) maximum.norm( A )
A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) maximum.norm( A )
This function returns the order n square matrix that is the sum of an implicit commutation matrix and the order n identity matrix quantity divided by two
N.matrix(n)
N.matrix(n)
n |
A positive integer matrix order |
Let be the order
implicit commutation matrix (i.e.,
).
and
the order
identity matrix. The formula for the matrix is
.
An order matrix.
If the argument is not an integer, the function displays an error message and stops. If the argument is less than two, the function displays an error message and stops.
Frederick Novomestky [email protected]
Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, SIAM Journal on Algebraic Discrete Methods, 1(4), December 1980, 422-449.
Magnus, J. R. and H. Neudecker (1999) Matrix Differential Calculus with Applications in Statistics and Econometrics, Second Edition, John Wiley.
N <- N.matrix( 3 ) print( N )
N <- N.matrix( 3 ) print( N )
This function returns the norm of the matrix
.
one.norm(x)
one.norm(x)
x |
a numeric vector or matrix |
Let be an
matrix.
The formula used to compute the norm is
.
This is merely the maximum absolute column sum of the
maxtris.
A numeric value.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
Golub, G. H. and C. F. Van Loan (1996). Matrix Computations, Third Edition, The John Hopkins University Press.
Horn, R. A. and C. R. Johnson (1985). Matrix Analysis, Cambridge University Press.
A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) one.norm( A )
A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) one.norm( A )
This function returns an n by n Pascal matrix.
pascal.matrix(n)
pascal.matrix(n)
n |
Order of the matrix |
In mathematics, particularly matrix theory and combinatorics, the Pascal matrix is a lower triangular matrix with binomial coefficients in the rows. It is easily obtained by performing an LU decomposition on the symmetric Pascal matrix of the same order and returning the lower triangular matrix.
An order matrix.
If the argument n is not a positive integer, the function presents an error message and stops.
Frederick Novomestky [email protected]
Aceto, L. and D. Trigiante, (2001). Matrices of Pascal and Other Greats, American Mathematical Monthly, March 2001, 232-245.
Call, G. S. and D. J. Velleman, (1993). Pascal's matrices, American Mathematical Monthly, April 1993, 100, 372-376.
Edelman, A. and G. Strang, (2004). Pascal Matrices, American Mathematical Monthly, 111(3), 361-385.
lu.decomposition
,
symmetric.pascal.matrix
P <- pascal.matrix( 4 ) print( P )
P <- pascal.matrix( 4 ) print( P )
This function returns a matrix which is a copy of matrix x into which the contents of matrix y have been inserted at the given row and column.
set.submatrix(x, y, row, col)
set.submatrix(x, y, row, col)
x |
a matrix |
y |
a matrix |
row |
an integer row number |
col |
an integer column number |
A matrix.
If the argument x is not a numeric matrix, then the function presents an error message and stops. If the argument y is not a numeric matrix, then the function presents an error message and stops. If the argument row is not a positive integer, then the function presents an error message and stops. If the argument col is not a positive integer, then the function presents an error message and stops. If the target row range does not overlap with the row range of argument x, then the function presents an error message and stops. If the target col range does not overlap with the col range of argument x, then the function presents an error message and stops.
Frederick Novomestky [email protected]
x <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) y <- matrix( seq( 1, 4, 1 ), nrow=2, byrow=TRUE ) z <- set.submatrix( x, y, 3, 3 )
x <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) y <- matrix( seq( 1, 4, 1 ), nrow=2, byrow=TRUE ) z <- set.submatrix( x, y, 3, 3 )
This function returns a matrix that has had its rows shifted downwards filling the above rows with the given fill value.
shift.down(A, rows = 1, fill = 0)
shift.down(A, rows = 1, fill = 0)
A |
a matrix |
rows |
the number of rows to be shifted |
fill |
the fill value which as a default is zero |
A matrix.
If the argument A is not a numeric matrix, then the function presents an error message and stops. If the argument rows is not a positive integer, then the function presents an error message and stops.
Frederick Novomestky [email protected]
A <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) shift.down( A, 1 ) shift.down( A, 3 )
A <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) shift.down( A, 1 ) shift.down( A, 3 )
This function returns a matrix that has been shifted n columns to the left filling the subsqeuent columns with the given fill value
shift.left(A, cols = 1, fill = 0)
shift.left(A, cols = 1, fill = 0)
A |
a matrix |
cols |
integer number of columns to be shifted to the left |
fill |
the fill value which as as a default zero |
A matrix.
If the argument A is not a numeric matrix, then the function presents an error message and stops. If the argument cols is not a positive integer, then the function presents an error message and stops.
Frederick Novomestky [email protected]
A <- matrix( seq( 1, 12, 1 ), nrow=3, byrow=TRUE ) shift.left( A, 1 ) shift.left( A, 2 )
A <- matrix( seq( 1, 12, 1 ), nrow=3, byrow=TRUE ) shift.left( A, 1 ) shift.left( A, 2 )
This function returns a matrix that has been shifted to the right n columns filling the previous columns with the given fill value.
shift.right(A, cols = 1, fill = 0)
shift.right(A, cols = 1, fill = 0)
A |
a matrix |
cols |
integer number of columns to be shifted to the right |
fill |
the fill which as default value zero |
A matrix.
If the argument A is not a numeric matrix, then the function presents an error message and stops. If the argument rows is not a positive integer, then the function presents an error message and stops.
Frederick Novomestky [email protected]
A <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) shift.right( A, 1 ) shift.right( A, 2 )
A <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) shift.right( A, 1 ) shift.right( A, 2 )
This function returns a matrix where the argument as been shifted up the given number of rows filling the bottom rows with the given fill value.
shift.up(A, rows = 1, fill = 0)
shift.up(A, rows = 1, fill = 0)
A |
a matrix |
rows |
integer number of rows |
fill |
fill value which as the default value of zero |
A matrix.
If the argument A is not a numeric matrix, then the function presents an error message and stops. If the argument rows is not a positive integer, then the function presents an error message and stops.
Frederick Novomestky [email protected]
A <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) shift.up( A, 1 ) shift.up( A, 3 )
A <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) shift.up( A, 1 ) shift.up( A, 3 )
This function returns the spectral norm of a real matrix.
spectral.norm(x)
spectral.norm(x)
x |
a numeric matrix or vector |
Let be an
real matrix. The
function computes the order
square matrixmatrix
.
The R function
eigen
is applied to this matrix to obtain the vector
of eigenvalues {\bf{\lambda }} = \left[ {\begin{array}{*{20}c}
{\lambda _1 } & {\lambda _2 } & \cdots & {\lambda _n } \\
\end{array}} \right]
. By construction the eigenvalues are in descending
order of value so that the largest eigenvalue is . Then
the spectral norm is
.
If
is a vector, then
is returned.
A numeric value.
If the argument x is not numeric, an error message is displayed and the function terminates.
If the argument is neither a matrix nor a vector, an error message is displayed and the
function terminates.
If the product matrix is negative definite, an error message
displayed and the function terminates.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
Golub, G. H. and C. F. Van Loan (1996). Matrix Computations, Third Edition, The John Hopkins University Press.
Horn, R. A. and C. R. Johnson (1985). Matrix Analysis, Cambridge University Press.
x <- matrix( c( 2, 4, 2, 1, 3, 1, 5, 2, 1, 2, 3, 3 ), nrow=3, ncol=4, byrow=TRUE ) spectral.norm( x )
x <- matrix( c( 2, 4, 2, 1, 3, 1, 5, 2, 1, 2, 3, 3 ), nrow=3, ncol=4, byrow=TRUE ) spectral.norm( x )
This function constructs and returns a Stirling matrix which is a lower triangular matrix containing the Stirling numbers of the second kind.
stirling.matrix(n)
stirling.matrix(n)
n |
A positive integer value |
The Stirling numbers of the second kind, , are used
in combinatorics to compute the number of ways a set of
objects
can be partitioned into
non-empty subsets
. The numbers are also
denoted by
\left\{ {\begin{array}{*{20}{c}}i\\j\end{array}} \right\}
. Stirling numbers of
the second kind can be computed recursively with the equation
.
The initial conditions for the recursion are
and
. The resultant numbers are organized
in an order
matrix
\left[ {\begin{array}{*{20}{c}}
{S_0^0}&0&0& \cdots &0\\
0&{S_1^1}&0& \cdots &0\\
0&{S_1^2}&{S_2^2}& \cdots &0\\
\cdots & \cdots & \cdots & \cdots & \cdots \\
0&{S_1^n}&{S_2^n}& \cdots &{S_n^n}
\end{array}} \right]
.
An order lower triangular matrix.
If the argument n is not a positive integer, the function presents an error message and stops.
Frederick Novomestky [email protected]
Aceto, L. and D. Trigiante (2001). Matrices of Pascal and Other Greats, American Mathematical Monthly, March 2001, 108(3), 232-245.
S <- stirling.matrix( 10 ) print( S )
S <- stirling.matrix( 10 ) print( S )
This function returns the inverse of a matrix using singular value
decomposition. If the matrix is a square matrix, this should be equivalent
to using the solve
function. If the matrix is not a square matrix,
then the result is the Moore-Penrose pseudo inverse.
svd.inverse(x)
svd.inverse(x)
x |
a numeric matrix |
A matrix.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
A <- matrix( c ( 1, 2, 2, 1 ), nrow=2, byrow=TRUE) invA <- svd.inverse( A ) print( A ) print( invA ) print( A %*% invA ) B <- matrix( c( -1, 2, 2 ), nrow=1, byrow=TRUE ) invB <- svd.inverse( B ) print( B ) print( invB ) print( B %*% invB )
A <- matrix( c ( 1, 2, 2, 1 ), nrow=2, byrow=TRUE) invA <- svd.inverse( A ) print( A ) print( invA ) print( A %*% invA ) B <- matrix( c( -1, 2, 2 ), nrow=1, byrow=TRUE ) invB <- svd.inverse( B ) print( B ) print( invB ) print( B %*% invB )
This function returns an n by n symmetric Pascal matrix.
symmetric.pascal.matrix(n)
symmetric.pascal.matrix(n)
n |
Order of the matrix |
In mathematics, particularly matrix theory and combinatorics, the symmetric Pascal matrix is a square matrix
from which you can derive binomial coefficients. The matrix is an order symmetric
matrix with typical element given by
{S_{i,j}} = {{n!} \mathord{\left/
{\vphantom {{n!} {\left[ {r!\;\left( {n - r} \right)!} \right]}}} \right.
\kern-\nulldelimiterspace} {\left[ {r!\;\left( {n - r} \right)!} \right]}}
where
and
. The binomial coefficients are elegantly recovered from the
symmetric Pascal matrix by performing an
decomposition as
.
An order matrix.
If the argument n is not a positive integer, the function presents an error message and stops.
Frederick Novomestky [email protected]
Call, G. S. and D. J. Velleman, (1993). Pascal's matrices, American Mathematical Monthly, April 1993, 100, 372-376.
Edelman, A. and G. Strang, (2004). Pascal Matrices, American Mathematical Monthly, 111(3), 361-385.
S <- symmetric.pascal.matrix( 4 ) print( S )
S <- symmetric.pascal.matrix( 4 ) print( S )
This function constructs a list of lists. The number of components in the high level list is n. Each of the n components is also a list. Each sub-list has n components each of which is an order n square matrix.
T.matrices(n)
T.matrices(n)
n |
a positive integer value for the order of the matrices |
Let
be a representative order
matrix created with function
E.matrices
.
The order matrix
is defined as follows
{{\bf{T}}_{i,j}} = \left\{ {\begin{array}{*{20}{c}}
{{{\bf{E}}_{i,j}}}&{i = j}\\
{{{\bf{E}}_{i,j}} + {{\bf{E}}_{j,i}}}&{i \ne j}
\end{array}} \right.
A list of components.
1 |
A list of |
2 |
A list of |
...
n |
A list of |
Each component of sublist
is a matrix
The argument n must be an integer value greater than or equal to 2.
Frederick Novomestky [email protected]
Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, SIAM Journal on Algebraic Discrete Methods, 1(4), December 1980, 422-449.
Magnus, J. R. and H. Neudecker (1999) Matrix Differential Calculus with Applications in Statistics and Econometrics, Second Edition, John Wiley.
T <- T.matrices( 3 )
T <- T.matrices( 3 )
This function constructs an order n Toeplitz matrix from the values in the order 2 * n - 1 vector x.
toeplitz.matrix(n, x)
toeplitz.matrix(n, x)
n |
a positive integer value for order of matrix greater than 1 |
x |
a vector of values used to construct the matrix |
The element T[i,j]
in the Toeplitz matrix is x[i-j+n]
.
An order n matrix.
If the argument n is not a positive integer, the function presents an error message and stops. If the length of x is not equal to 2 * n - 1, the function presents an error message and stops.
Frederick Novomestky [email protected]
Monahan, J. F. (2011). Numerical Methods of Statistics, Cambridge University Press.
T <- toeplitz.matrix( 4, seq( 1, 7 ) ) print( T )
T <- toeplitz.matrix( 4, seq( 1, 7 ) ) print( T )
This function constructs an order n * ( n + 1 ) / 2 identity matrix and an order matrix u that that maps the ordered pair of indices (i,j) i=j, ..., n; j=1, ..., n to a column in this identity matrix.
u.vectors(n)
u.vectors(n)
n |
a positive integer value for the order of underlying matrices |
The function firsts constructs an identity matrix of order .
is the column vector in the order
identity
matrix for column
.
A list with two named components
k |
order |
I |
order |
If the argument is not an integer, the function displays an error message and stops. If the argument is less than two, the function displays an error message and stops.
Frederick Novomestky [email protected]
Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, SIAM Journal on Algebraic Discrete Methods, 1(4), December 1980, 422-449.
Magnus, J. R. and H. Neudecker (1999) Matrix Differential Calculus with Applications in Statistics and Econometrics, Second Edition, John Wiley.
u <- u.vectors( 3 )
u <- u.vectors( 3 )
Returns the lower triangle including the diagonal of a square numeric matrix.
upper.triangle(x)
upper.triangle(x)
x |
a matrix |
A matrix.
Frederick Novomestky [email protected]
Bellman, R. (1987). Matrix Analysis, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics.
A <- matrix( seq( 1, 9, 1 ), nrow=3, byrow=TRUE ) upper.triangle( A )
A <- matrix( seq( 1, 9, 1 ), nrow=3, byrow=TRUE ) upper.triangle( A )
This function returns an m by n matrix of the powers of the alpha vector
vandermonde.matrix(alpha, n)
vandermonde.matrix(alpha, n)
alpha |
A numerical vector of values |
n |
The column dimension of the Vandermonde matrix |
In linear algebra, a Vandermonde matrix is an matrix with terms
of a geometric progression of an
parameter vector
{\bf{\alpha }} = {\left[ {\begin{array}{*{20}{c}}
{{\alpha _1}}&{{\alpha _2}}& \cdots &{{\alpha _m}}
\end{array}} \right]^\prime }
such that V\left( {\bf{\alpha }} \right) = \left[ {\begin{array}{*{20}{c}}
1&{{\alpha _1}}&{\alpha _1^2}& \cdots &{\alpha _1^{n - 1}}\\
1&{{\alpha _2}}&{\alpha _2^2}& \cdots &{\alpha _2^{n - 1}}\\
1&{{\alpha _3}}&{\alpha _3^2}& \cdots &{\alpha _3^{n - 1}}\\
\cdots & \cdots & \cdots & \cdots & \cdots \\
1&{{\alpha _m}}&{\alpha _m^2}& \cdots &{\alpha _m^{n - 1}}
\end{array}} \right]
.
A matrix.
Frederick Novomestky [email protected]
Horn, R. A. and C. R. Johnson (1991). Topics in matrix analysis, Cambridge University Press.
alpha <- c( .1, .2, .3, .4 ) V <- vandermonde.matrix( alpha, 4 ) print( V )
alpha <- c( .1, .2, .3, .4 ) V <- vandermonde.matrix( alpha, 4 ) print( V )
This function returns a column vector that is a stack of the columns of x, an m by n matrix.
vec(x)
vec(x)
x |
a matrix |
A matrix with rows and one column.
Frederick Novomestky [email protected]
Magnus, J. R. and H. Neudecker (1999) Matrix Differential Calculus with Applications in Statistics and Econometrics, Second Edition, John Wiley.
x <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) print( x ) vecx <- vec( x ) print( vecx )
x <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) print( x ) vecx <- vec( x ) print( vecx )
This function returns a stack of the lower triangular matrix of a square matrix as a matrix with 1 column and n * ( n + 1 ) / 2 rows
vech(x)
vech(x)
x |
a matrix |
A matrix with rows and one column.
Frederick Novomestky [email protected]
Magnus, J. R. and H. Neudecker (1999) Matrix Differential Calculus with Applications in Statistics and Econometrics, Second Edition, John Wiley.
x <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) print( x ) y <- vech( x ) print( y )
x <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) print( x ) y <- vech( x ) print( y )