r-cran-matrixcalc-1.0.3/000077500000000000000000000000001274367517000150365ustar00rootroot00000000000000r-cran-matrixcalc-1.0.3/DESCRIPTION000077500000000000000000000014671274367517000165570ustar00rootroot00000000000000Package: matrixcalc Version: 1.0-3 Date: 2012-09-12 Title: Collection of functions for matrix calculations Author: Frederick Novomestky Maintainer: Frederick Novomestky Depends: R (>= 2.0.1) 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. License: GPL (>= 2) Packaged: 2012-09-14 22:54:49 UTC; fred Repository: CRAN Date/Publication: 2012-09-15 14:22:14 r-cran-matrixcalc-1.0.3/MD5000066400000000000000000000147061274367517000153560ustar00rootroot00000000000000d9c5fa2301d05f637d491d077fec0faa *DESCRIPTION 4be87d2e3c549f8c524f6b2eb86399a4 *NAMESPACE 2c8d8a78f8b955c2f2f586f5bacf3247 *R/D.matrix.R c944e010361d98b90fa512d4965c2383 *R/E.matrices.R 71f6be247b2345ec1b5872466dca2431 *R/H.matrices.R bac34a744518cce7b5734850d45c2c0d *R/K.matrix.R 6bfb2781f2ec3698bfc5bd1ddcfe18b4 *R/L.matrix.R 27337ba4230b62fca4d790395cabc6c7 *R/N.matrix.R d96685a05d885d85e0e6b1dc039c8636 *R/T.matrices.R 731b97ec42f006705fa4f58c63d58331 *R/commutation.matrix.R 62d0ea817d89796582fa953f9c1b79f4 *R/creation.matrix.R 4f5d46a65ee100372c0c80a4b7d0603a *R/direct.prod.R 1b39be5b4507e9602c51b1896e6d3422 *R/direct.sum.R 5d17bc6c0d27ee7068d386a44ba72197 *R/duplication.matrix.R 8402bc1d6f15c51b509a6994f1a479bd *R/elimination.matrix.R c24998138a3dd7b1dcc2f407a3b480c6 *R/entrywise.norm.R 2af94e74841a173131de053da13ab533 *R/fibonacci.matrix.R 50258bc682374273a28a380dae663d6d *R/frobenius.matrix.R b020074d548aa68ce6c9755f3c1b6597 *R/frobenius.norm.R 53a9d15f46b3e8466f87e99cabb92b5a *R/frobenius.prod.R e9c899e4c92acc318be7601edc455274 *R/hadamard.prod.R 20c120bdd52fdf11e119fd462857c3a2 *R/hankel.matrix.R 94d010622099c5df6d00a5ee1b44c9be *R/hilbert.matrix.R 03f9f1cc9600fdca28156874500c17b0 *R/hilbert.schmidt.norm.R bfd6ddd08302469dbaccc423d4d5bb7d *R/inf.norm.R d76fb3d0f200436c6afd92d564e2beaa *R/is.diagonal.matrix.R d6926822047856a2cddfb43accc7d1f9 *R/is.idempotent.matrix.R 69c3ad7f0dd3faa8bdb8f5bbe87d14c0 *R/is.indefinite.R f19a39fd4514178e639f23bde97f57d2 *R/is.negative.definite.R d95e8f31b7d26c37d467f3775bd34018 *R/is.negative.semi.definite.R 585936c334ddb173cb10d2db939ccbcb *R/is.non.singular.matrix.R 58c2d05f1d185786ce9ae9fe19775007 *R/is.positive.definite.R 0d022dbd6264554b4c4ddc99a8f11298 *R/is.positive.semi.definite.R e564d72c304cf0642a4725a14f6db0c1 *R/is.singular.matrix.R a4ec06b010bf211e602b4280f71a0bb1 *R/is.skew.symmetric.matrix.R b2802b610ed8ed62f80f9ee033daca6a *R/is.square.matrix.R 12e88ca7d5a56f3cefe9d9f58b28303d *R/is.symmetric.matrix.R 907309ee331e787525665baf8d4d7bbb *R/lower.triangle.R 79db8c243e35db286b07288baa42a79e *R/lu.decomposition.R 6a041d084671936aeea6dc60f7d03e81 *R/matrix.inverse.R 8e8317708b130adbc237bdef10a52429 *R/matrix.power.R 7d534f91782c58f31c0fc0c28a320f4d *R/matrix.rank.R 3ca0a03e3e14cbb0a1fee4469da0fba0 *R/matrix.trace.R 50226dcc08883e432a536c5d2e53740c *R/maximum.norm.R d64f99922b89078fde55fddb62295d78 *R/one.norm.R c2268f4acabb63a19e57c36b86176de3 *R/pascal.matrix.R a27bbcb2fcbe235cd7a88af3f84e9cd9 *R/s.R b613d92fed28d6f3eb0e7af25dd24996 *R/set.submatrix.R 60db620761b455d664794429630a6068 *R/shift.down.R 84fdb4a3e40935401b3c3a7d58f6746a *R/shift.left.R 207fe5b7689a24f12de2d5c6e90812f3 *R/shift.right.R aebd7ca6804ca7d75f1e994bd53f3822 *R/shift.up.R f2b024e0a9d6a0681aa925dc1b689193 *R/spectral.norm.R 8ac6dda72539bbfebcd90167b8e417cc *R/stirling.matrix.R 5d812285c95d446c8c0403e1798298fa *R/svd.inverse.R 76f90e460e592bb3aff31e5b30972874 *R/symmetric.pascal.matrix.R 4b0d3e6ed0f288d2e377680be9865398 *R/toeplitz.matrix.R adaba9414c7856677859ee1789cbe572 *R/u.vectors.R aa3e0e4259548ec8a43d1b0651fe36af *R/upper.triangle.R e4051eb23562f1d7659d03a8a190a262 *R/vandermonde.matrix.R 5e252bd16e54c9bcb932d6a0c33e521c *R/vec.R 8cd0039aa5da08f8a764a25aa9706605 *R/vech.R 63a7ae735ccf219a80e88ef3bae87086 *man/D.matrix.Rd 023909c1a277a2bd0c592ff30ece8ac9 *man/E.matrices.Rd 0ff598aae741da702998f8220b1ac463 *man/H.matrices.Rd bef1921a68d926facc840e366aef6a9f *man/K.matrix.Rd 0f93b7e85ce4c5db800932b9242a6684 *man/L.matrix.Rd 8948f8a681f85bd52e67767f10038476 *man/N.matrix.Rd 03e6369eccd779ed2af5eaf421656356 *man/T.matrices.Rd 6752875108e1544d7c14d3cd0387e448 *man/commutation.matrix.Rd 28304f5fd2c8dbf8e31fe24e507c0dc8 *man/creation.matrix.Rd 1342e1d89260cbb388b038d9a599733f *man/direct.prod.Rd 13792f63b29ba0ddbc6b3137616bbcdc *man/direct.sum.Rd 2f2b3389439d9dc3bfbd2b19ecf42521 *man/duplication.matrix.Rd c07f02e353187d04b116f935878b071d *man/elimination.matrix.Rd 7cd36f9f6319dd87ae3e48957d0267a9 *man/entrywise.norm.Rd 4db058a6b1a21f97c9a32fa59a462667 *man/fibonacci.matrix.Rd 2f91d3319b251271d52f21654186f39f *man/frobenius.matrix.Rd 039cadd7ccb2184e20cf1219d25ceff1 *man/frobenius.norm.Rd 6d01d9763c8a2fdb10efb2ab4b6b570c *man/frobenius.prod.Rd f706f64e644a884f682ea608609ab0a3 *man/hadamard.prod.Rd 31c3e641fd9002e4784bdd36fca065de *man/hankel.matrix.Rd dc6523f5ff55b1d2949efe7497d484b3 *man/hilbert.matrix.Rd 764c3c2e2d11ae26f553458fdb6c5297 *man/hilbert.schmidt.norm.Rd 958394a4b18fbe3f781289708921de4d *man/inf.norm.Rd febd94d3d26ff570c9b9c71499a65927 *man/is.diagonal.matrix.Rd c0f25e97d29757e91063978f14a5fcac *man/is.idempotent.matrix.Rd 69b2efde04bd571f56d58fe6820826b1 *man/is.indefinite.Rd 2417dc0863a48332d082ffb1d9e6b6e7 *man/is.negative.definite.Rd 1728c0c1239364f445451079d721cbb1 *man/is.negative.semi.definite.Rd 219342065dec20759bb075439508413c *man/is.non.singular.matrix.Rd f0beeb3d2625c53f30bf495dd4c4698b *man/is.positive.definite.Rd 96257d015034244a8d948c65d5a8c706 *man/is.positive.semi.definite.Rd 4f3954a1d3cf0caa90d452a6c5e988ae *man/is.singular.matrix.Rd 396a1ee67b212abc7b2bbbc09fd0b509 *man/is.skew.symmetric.matrix.Rd e072a8ce686c5461d82cd50996632055 *man/is.square.matrix.Rd 84ba6c4913385303101e796de1762a44 *man/is.symmetric.matrix.Rd b471a239d55da5b3eb21b722c6bcf32a *man/lower.triangle.Rd eef6e4ae7bf84f78fe69fce0198f9c94 *man/lu.decomposition.Rd 29040c6a92c46b449be9db10446d1f41 *man/matrix.inverse.Rd d250344b337e0097eb3ad0efb547942b *man/matrix.power.Rd 2353b602e73dc629181ef20f72bcf82c *man/matrix.rank.Rd 3c6e5bf8ed52f9901930d2aca28807bc *man/matrix.trace.Rd 223e3c78b976ee1455edab492821c6d0 *man/maximum.norm.Rd f7f8c279e3f58835374ad013cef2697f *man/one.norm.Rd adb798ccbe69962b270f50027708b4da *man/pascal.matrix.Rd 1d71b2bfbfc1955edb8400f5093b6669 *man/s.Rd 00748a51b18bbb984167df996d4924fb *man/set.submatrix.Rd 96b65cde97f647500f86836b29e4dcb0 *man/shift.down.Rd d81aebc918e739102aba01ef9d443280 *man/shift.left.Rd 39ddc9ab8e39d20db36f97a6f497f6ef *man/shift.right.Rd 807b1e1f57e0dbb1004d63197c6b17ce *man/shift.up.Rd 37a382a887d158676b85faa99695158a *man/spectral.norm.Rd a2d7e641d88e593f540a1e119692a033 *man/stirling.matrix.Rd 8cb1322739b7a8f9dcea2aa75c864e23 *man/svd.inverse.Rd 795bdbe5f7976766484220afe929b1c1 *man/symmetric.pascal.matrix.Rd 4671880f5c35e064f0fbf461ffed81f6 *man/toeplitz.matrix.Rd 49e344ba77c0fd0f5a2da916e0a8050c *man/u.vectors.Rd 3ee4edde7e1b28d5260a246b1d0e0dd7 *man/upper.triangle.Rd 0b90fc86c534c84fcbb4d3c1b863d7ff *man/vandermonde.matrix.Rd d84a2248b908e8b5e6a5de02b6c4580e *man/vec.Rd 83446510b7ff4ee195c33fd56f538b33 *man/vech.Rd r-cran-matrixcalc-1.0.3/NAMESPACE000077500000000000000000000030641274367517000162630ustar00rootroot00000000000000exportPattern( "^[[:alpha:]]+" ) export( "commutation.matrix", "creation.matrix", "D.matrix", "direct.prod", "direct.sum", "duplication.matrix", "E.matrices", "elimination.matrix", "entrywise.norm", "fibonacci.matrix", "frobenius.matrix", "frobenius.norm", "frobenius.prod", "H.matrices", "hadamard.prod", "hankel.matrix", "hilbert.matrix", "hilbert.schmidt.norm", "inf.norm", "is.diagonal.matrix", "is.idempotent.matrix", "is.indefinite", "is.negative.definite", "is.negative.semi.definite", "is.non.singular.matrix", "is.positive.definite", "is.positive.semi.definite", "is.singular.matrix", "is.skew.symmetric.matrix", "is.square.matrix", "is.symmetric.matrix", "K.matrix", "L.matrix", "lower.triangle", "lu.decomposition", "matrix.inverse", "matrix.power", "matrix.rank", "matrix.trace", "maximum.norm", "N.matrix", "one.norm", "pascal.matrix", "%s%", "set.submatrix", "shift.down", "shift.left", "shift.right", "shift.up", "spectral.norm", "stirling.matrix", "svd.inverse", "symmetric.pascal.matrix", "T.matrices", "toeplitz.matrix", "u.vectors", "upper.triangle", "vandermonde.matrix", "vec", "vech" ) r-cran-matrixcalc-1.0.3/R/000077500000000000000000000000001274367517000152375ustar00rootroot00000000000000r-cran-matrixcalc-1.0.3/R/D.matrix.R000077500000000000000000000015041274367517000170530ustar00rootroot00000000000000D.matrix <- function( n ) { ### ### This function constructs the linear transformation D that maps vech(A) ### to vec(A) when A is a symmetric matrix ### ### Arguments ### n = a positive integer for the order of a matrix ### if( missing( n ) ) stop( "argument n is missing" ) if ( !is.numeric( n ) ) stop( "argument n is not numeric" ) if ( n != trunc( n ) ) stop( "argument n is not an integer" ) if ( n < 2 ) stop( "argument n is less than 2" ) p <- n * ( n + 1 ) /2 nsq <- n * n Dt <- matrix( 0, nrow=p, ncol=nsq ) T <- T.matrices( n ) u <- u.vectors( n ) k <- u$k I <- u$I for ( j in 1:n ) { for ( i in j:n ) { Dt <- Dt + I[,k[i,j]] %*% t( vec( T[[i]][[j]] ) ) } } return( t( Dt ) ) } r-cran-matrixcalc-1.0.3/R/E.matrices.R000077500000000000000000000017021274367517000173570ustar00rootroot00000000000000E.matrices <- function( n ) { ### ### This function creates a list of lists. The number of components ### in the higher level list is n. For each component i in the ### higher level list, the number of components in the sub-list ### is n. Each component j of the sub-list is an n by n matrix ### e_i %*% t ( e_j ). Each of the arrays is a vector in an ### n by n identity matrix ### ### argument ### n = a positive integer value greater than or equal to 2 ### if( missing( n ) ) stop( "argument n is missing" ) if ( !is.numeric( n ) ) stop( "argument n is not numeric" ) if ( n != trunc( n ) ) stop( "argument n is not an integer" ) if ( n < 2 ) stop( "argument n is less than 2" ) I <- diag( rep( 1, n ) ) E <- list() for ( i in 1:n ) { E[[i]] <- list() for ( j in 1:n ) { E[[i]][[j]] <- I[i,] %o% I[j,] } } return( E ) } r-cran-matrixcalc-1.0.3/R/H.matrices.R000077500000000000000000000024021274367517000173600ustar00rootroot00000000000000H.matrices <- function( r, c=r ) { ### ### This function returns a list of lists. The length of the high ### level list is r. Each component i of the high level list is ### a list of c components. Each sub-component j of main component i ### is an r by c matrix. Each matrix is the outer product of column ### i in the r by r identity and column j of the c by c identity matrix ### ### Arguments ### r = a positive integer for the number of rows in each matrix ### c = a positive integer for the number of columns in each matrix ### if ( missing( r ) ) stop( "argument r is missing" ) if ( !is.numeric( r ) ) stop( "argument r is not numeric" ) if ( r != trunc( r ) ) stop( "argument r is not an integer" ) if ( r < 2 ) stop( "argument r is less than 2" ) if ( !is.numeric( c ) ) stop( "argument c is not numeric" ) if ( c != trunc( c ) ) stop( "argument c is not an integer" ) if ( c < 2 ) stop( "argument c is less than 2" ) Ir <- diag( rep( 1, r ) ) Ic <- diag( rep( 1, c ) ) H <- list() for ( i in 1:r) { H[[i]] <- list() for ( j in 1:c ) { H[[i]][[j]] <- Ir[i,] %o% Ic[j,] } } return( H ) } r-cran-matrixcalc-1.0.3/R/K.matrix.R000077500000000000000000000017741274367517000170730ustar00rootroot00000000000000K.matrix <- function( r, c=r ) { ### ### This function constructs the rc by rc commutation matrix ### ### Arguments ### r = a positive integer value for the number of rows in the H matrices ### c = a positive integer value for the number of columns in the H matrices ### if ( missing( r ) ) stop( "argument r is missing" ) if ( !is.numeric( r ) ) stop( "argument r is not numeric" ) if ( r != trunc( r ) ) stop( "argument r is not an integer" ) if ( r < 2 ) stop( "argument r is less than 2" ) if ( !is.numeric( c ) ) stop( "argument c is not numeric" ) if ( c != trunc( c ) ) stop( "argument c is not an integer" ) if ( c < 2 ) stop( "argument c is less than 2" ) H <- H.matrices( r, c ) p <- r * c K <- matrix( 0, nrow=p, ncol=p ) for ( i in 1:r ) { for ( j in 1:c ) { Hij <- H[[i]][[j]] K <- K + ( Hij %x% t( Hij ) ) } } return( K ) } r-cran-matrixcalc-1.0.3/R/L.matrix.R000077500000000000000000000014521274367517000170650ustar00rootroot00000000000000L.matrix <- function( n ) { ### ### This function constructs the elimination matrix as a mapping ### from vec(A) to vech(A) ### ### Arguments ### n = a positive integer value for the order of the matrix ### if ( missing( n ) ) stop( "argument n is missing" ) if ( !is.numeric( n ) ) stop( "argument n is not numeric" ) if ( n != trunc( n ) ) stop( "argument n is not an integer" ) if ( n < 2 ) stop( "argument n is less than 2" ) u <- u.vectors( n ) E <- E.matrices( n ) k <- u$k I <- u$I p <- n * ( n + 1 ) / 2 nsq <- n * n L <- matrix( 0, nrow=p, ncol=nsq) for ( j in 1:n ) { for ( i in j:n ) { L <- L + I[,k[i,j]] %*% t( vec( E[[i]][[j]] ) ) } } return( L ) } r-cran-matrixcalc-1.0.3/R/N.matrix.R000077500000000000000000000011241274367517000170630ustar00rootroot00000000000000N.matrix <- function( n ) { ### ### This function returns the n*n by n*n matrix that is the sum of the ### implicit commutation matrix Kn and an identity matrix ### ### Arguments ### n = a positive integer value for the underlying matrix ### if ( missing( n ) ) stop( "argument n is missing" ) if ( !is.numeric( n ) ) stop( "argument n is not numeric" ) if ( n != trunc( n ) ) stop( "argument n is not an integer" ) if ( n < 2 ) stop( "argument n is less than 2" ) return( ( K.matrix( n ) + diag( rep( 1, n * n ) ) ) / 2 ) } r-cran-matrixcalc-1.0.3/R/T.matrices.R000077500000000000000000000017231274367517000174010ustar00rootroot00000000000000T.matrices <- function( n ) { ### ### This function constructs a list of lists. For each high level list i, ### the component is a list of n components. These components are derived ### from the list of lists E generated by the function E.matrices ### ### Argument ### n = a positive integer for the order of an underlying square matrix ### if( missing( n ) ) stop( "argument n is missing" ) if ( !is.numeric( n ) ) stop( "argument n is not numeric" ) if ( n != trunc( n ) ) stop( "argument n is not an integer" ) if ( n < 2 ) stop( "argument n is less than 2" ) E <- E.matrices( n ) T <- list() for ( i in 1:n ) { T[[i]] <- list() for ( j in 1:n ) { if ( i == j ) { T[[i]][[j]] <- E[[i]][[j]] } else { T[[i]][[j]] <- E[[i]][[j]] + E[[j]][[i]] } } } return( T ) } r-cran-matrixcalc-1.0.3/R/commutation.matrix.R000077500000000000000000000003511274367517000212260ustar00rootroot00000000000000commutation.matrix <- function( r, c=r ) { ### ### this function returns a square matrix with p = r * c rows and columns ### ### Parameters ### m = integer rows ### n = integer columns ### return( K.matrix( r, c ) ) } r-cran-matrixcalc-1.0.3/R/creation.matrix.R000077500000000000000000000012731274367517000204770ustar00rootroot00000000000000creation.matrix <- function( n ) { ### ### this function returns an order n creation matrix that is useful ### in numerical mathematics such as the solution of differential equations. ### ### argument ### n = a positive integer greater than 1 ### if ( !is.numeric( n ) ) stop( "argument n is not numeric" ) if ( !is.vector( n ) ) stop( "argument n is not the proper data type" ) if ( length( n ) > 1 ) stop( "argument n is not a scalr number" ) if ( n != trunc( n ) ) stop( "argument n is not an integer" ) if ( n < 2 ) stop( "argument n is less than 2" ) H <- shift.down( diag( seq( 1, n ) ) ) return( H ) } r-cran-matrixcalc-1.0.3/R/direct.prod.R000077500000000000000000000037041274367517000176060ustar00rootroot00000000000000direct.prod <- function( x, y ) { ### ### This function computes the direct product of two vectors or ### matrices resulting in a matrix ### ### Arguments ### x = a numeric matrix or vector ### y = a numeric matrix or vector ### if ( is.vector( x ) ) { A <- matrix( x ) } else { if ( is.matrix( x ) ) { A <- x } else { stop( "Argument x is not a matrix or vector" ) } } if ( is.vector( y ) ) { B <- matrix( y ) } else { if ( is.matrix( y ) ) { B <- y } else { stop( "Argument y is not a matrix or vector" ) } } ### ### construct a list of lists. The number of elements in the higher level ### is the number of rows in A. The number of elements in the lower level ### is the number of columns in A. The value for higher level index i ### and lower level index j is A[i,j] * B ### matrices <- list() for ( i in 1:nrow( A ) ) { matrices[[i]] <- list() for ( j in 1:ncol( A ) ) { matrices[[i]][[j]] <- A[i,j] * B } } ### ### construct a list of matrices. The number of elements is the number ### of rows in A. The value for element i is the column binding of all the elements ### in the higher level matrices[[i]]. ### row.matrices <- list() for ( i in 1:nrow( A ) ) { row.matrices[[i]] <- matrices[[i]][[1]] if ( ncol( A ) > 1 ) { for ( j in 2:ncol( A ) ) { row.matrices[[i]] <- cbind( row.matrices[[i]], matrices[[i]][[j]] ) } } } ### ### construct the result matrix C as the row binding of all of the elements in row.matrices ### C <- row.matrices[[1]] if ( length( row.matrices ) > 1 ) { for ( i in 2:length( row.matrices ) ) { C <- rbind( C, row.matrices[[i]] ) } } return( C ) } r-cran-matrixcalc-1.0.3/R/direct.sum.R000077500000000000000000000016021274367517000174410ustar00rootroot00000000000000direct.sum <- function( x, y ) { ### ### This function computes the direct sum of two vectors or ### matrices resulting in a block diagonal matrix ### ### Arguments ### x = a numeric matrix or vector ### y = a numeric matrix or vector ### matrices <- list() if ( is.vector( x ) ) { A <- matrix( x ) } else { if ( is.matrix( x ) ) { A <- x } else { stop( "Argument x is not a matrix or vector" ) } } if ( is.vector( y ) ) { B <- matrix( y ) } else { if ( is.matrix( y ) ) { B <- y } else { stop( "Argument y is not a matrix or vector" ) } } C <- rbind( cbind( A, matrix( 0, nrow=nrow(A), ncol=ncol(B) ) ), cbind( matrix( 0, nrow=nrow(B), ncol=ncol(A) ), B ) ) return( C ) } r-cran-matrixcalc-1.0.3/R/duplication.matrix.R000077500000000000000000000004521274367517000212040ustar00rootroot00000000000000duplication.matrix <- function( n=1 ) { ### ### this function returns a matrix sith 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 ### ### Parameter ### n = the order of the matrix ### return( D.matrix( n ) ) } r-cran-matrixcalc-1.0.3/R/elimination.matrix.R000077500000000000000000000004471274367517000212050ustar00rootroot00000000000000elimination.matrix <- function( n ) { ### ### this function returns a matrix sith n * n comuns and n * (n + 1 ) / 2 ### rows that transforms vec( A ) to vech( A ) where A is a symmetric n by n matrix ### ### Parameter ### n = the order of the matrix ### return( L.matrix( n ) ) } r-cran-matrixcalc-1.0.3/R/entrywise.norm.R000077500000000000000000000015511274367517000203720ustar00rootroot00000000000000entrywise.norm <- function( x, p ) { ### ### This function computes the entrywise norm in which the absolute value of ### each element of matrix x is raised to the power p and the norm is the ### sum of these quantities ### ### arguments ### x = a numeric matrix or vector ### p = a real value for the power ### if ( !is.numeric( x ) ) { stop( "argument x is not numeric" ) } if ( is.matrix( x ) ) { Xmat <- x } else { if ( is.vector( x ) ) { Xmat <- matrix( x, nrow=length(x), ncol=1 ) } else { stop( "argument x is neither vector nor matrix" ) } } if ( p == 0 ) { stop( "exponent p is zero" ) } if ( is.infinite( p ) ) { return( maximum.norm( x ) ) } return( ( sum( abs( Xmat ) ^ p ) ) ^ ( 1 / p ) ) } r-cran-matrixcalc-1.0.3/R/fibonacci.matrix.R000077500000000000000000000020501274367517000206020ustar00rootroot00000000000000fibonacci.matrix <- function( n ) { ### ### This function returns the order n + 1 Fibonacci matrix which ### is a square matrix derived from the Fibonacci sequence ### ### argument ### n = a positive integer ### if ( !is.numeric( n ) ) stop( "argument n is not numeric" ) if ( !is.vector( n ) ) stop( "argument n is not the proper data type" ) if ( length( n ) > 1 ) stop( "argument n is not a scalr number" ) if ( n != trunc( n ) ) stop( "argument n is not an integer" ) if ( n < 1 ) stop( "argument n is less than 2" ) np1 <- n + 1 np2 <- n + 2 f <- rep( 0, np2 ) f[1] <- 1 f[2] <- 1 j <- 3 while ( j <= np2 ) { f[j] <- f[j-1] + f[j-2] j <- j + 1 } F <- matrix( 0, nrow=np1, ncol=np1 ) for ( i in 0:n ) { ip1 <- i + 1 for ( j in 0:n ) { jp1 <- j + 1 if ( i - j + 1 >= 0 ) { F[ip1,jp1] <- f[i - j + 2] } } } return( F ) } r-cran-matrixcalc-1.0.3/R/frobenius.matrix.R000077500000000000000000000013231274367517000206630ustar00rootroot00000000000000frobenius.matrix <- function( n ) { ### ### this function returns an order n Frobenius matrix that is useful ### in numerical mathematics. ### ### argument ### n = a positive integer greater than 1 ### if ( !is.numeric( n ) ) stop( "argument n is not numeric" ) if ( !is.vector( n ) ) stop( "argument n is not the proper data type" ) if ( length( n ) > 1 ) stop( "argument n is not a scalr number" ) if ( n != trunc( n ) ) stop( "argument n is not an integer" ) if ( n < 2 ) stop( "argument n is less than 2" ) F <- shift.down( diag( 1, n ) ) nm1 <- n - 1 j <- 0:nm1 F[,n] <- (-1)^(nm1-j) * choose( n,j) return( F ) } r-cran-matrixcalc-1.0.3/R/frobenius.norm.R000077500000000000000000000004131274367517000203310ustar00rootroot00000000000000frobenius.norm <- function( x ) { ### ### This function is a wrapper function that uses the entrywise.norm function ### with p = 2 to obtain the fronbenius norm ### ### argument ### x = a numeric matrix or vector ### return( entrywise.norm( x, 2 ) ) } r-cran-matrixcalc-1.0.3/R/frobenius.prod.R000077500000000000000000000005311274367517000203230ustar00rootroot00000000000000frobenius.prod <- function( x, y ) { ### ### this function calculates the Frobenius inner product product of two matrices x and y. ### the matrices must the same row and column order ### ### Parameters ### x = a numeric matrix or vector object ### y = a numeric matrix or vector object ### return( sum( hadamard.prod(x, y) ) ) } r-cran-matrixcalc-1.0.3/R/hadamard.prod.R000077500000000000000000000023211274367517000200670ustar00rootroot00000000000000hadamard.prod <- function( x, y ) { ### ### this function calculates the Hadamard product of two matrices x and y. ### the matrices must the same row and column order ### ### Parameters ### x = a numeric matrix object ### y = a numeric matrix object ### if ( !is.numeric( x ) ) { stop( "argument x is not numeric" ) } if ( !is.numeric( y ) ) { stop( "argument y is not numeric" ) } if ( is.matrix( x ) ) { Xmat <- x } else { if ( is.vector( x ) ) { Xmat <- matrix( x, nrow=length(x), ncol=1 ) } else { stop( "argument x is neither a matrix or a vector" ) } } if ( is.matrix( y ) ) { Ymat <- y } else { if ( is.vector( y ) ) { Ymat <- matrix( y, nrow=length(x), ncol=1 ) } else { stop( "argument x is neither a matrix or a vector" ) } } if ( nrow( Xmat ) != nrow( Ymat ) ) stop( "argumentx x and y do not have the same row order" ) if ( ncol( Xmat ) != ncol( Ymat ) ) stop( "arguments x and y do not have the same column order" ) return( Xmat * Ymat ) } r-cran-matrixcalc-1.0.3/R/hankel.matrix.R000077500000000000000000000020761274367517000201370ustar00rootroot00000000000000hankel.matrix <- function( n, x ) { ### ### This function returns an order n Hankel matrix from the values in ### the order m vector x derived by a circular shift of the values ### in this vector to the left. Hankel matrices are formed when a given sequence ### of output data and a realization of an underlying state-space or ### hidden Markov model is desired. ### ### arguments ### n = a positive integer value for the order of the Hankel matrix ### x = an order 2 * n + 1 vector of numeric values ### if ( !is.numeric( n ) ) stop( "argument n is not numeric" ) if ( n != trunc( n ) ) stop( "argument n ix not an integer" ) if ( n < 2 ) stop( "argument n is less than 2" ) if ( !is.vector( x ) ) stop( "argument x is not a vector" ) m <- length( x ) if ( m < n ) stop( "length of argument x is less than n" ) y <- x H <- matrix( 0, nrow=n, ncol=n ) H[1,] <- y[1:n] for ( i in 2:n ) { y <- c( y[2:m], y[1] ) H[i,] <- y[1:n] } return( H ) } r-cran-matrixcalc-1.0.3/R/hilbert.matrix.R000077500000000000000000000005731274367517000203260ustar00rootroot00000000000000hilbert.matrix <- function(n) { ### ### this function returns an n by n Hilbert matrix ### ### Parameter ### n = the row (column) dimension of the matrix ### if ( n != trunc( n ) ) stop( "argument n is not an integer" ) if ( n < 2 ) stop( "argument n is less than 2" ) i <- 1:n X <- 1 / outer(i - 1, i, "+") return( X ) } r-cran-matrixcalc-1.0.3/R/hilbert.schmidt.norm.R000077500000000000000000000004211274367517000214170ustar00rootroot00000000000000hilbert.schmidt.norm <- function( x ) { ### ### This function is a wrapper function that uses the entrywise.norm function ### with p = 2 to obtain the fronbenius norm ### ### argument ### x = a numeric matrix or vector ### return( entrywise.norm( x, 2 ) ) } r-cran-matrixcalc-1.0.3/R/inf.norm.R000077500000000000000000000011551274367517000171150ustar00rootroot00000000000000inf.norm <- function( x ) { ### ### This function returns the p = Inf norm wich is the maximum absolute row sum ### of the matrix x ### ### argument ### x = a numeric vector or matrix ### if ( !is.numeric( x ) ) { stop( "argument x is not numeric" ) } if ( is.matrix( x ) ) { Xmat <- x } else { if ( is.vector( x ) ) { Xmat <- matrix( x, nrow=length(x), ncol=1 ) } else { stop( "argument x is neither a matrix nor a vector" ) } } norm <- max( apply( abs( Xmat ), 1, sum ) ) return( norm ) } r-cran-matrixcalc-1.0.3/R/is.diagonal.matrix.R000077500000000000000000000010431274367517000210560ustar00rootroot00000000000000is.diagonal.matrix <- function( x, tol=1e-8 ) { ### ### this function returns TRUE if the off diagonal elements in absolute ### value are less than the given tolerance and FALSE otherwise ### ### arguments ### x = a numeric square matrix ### tol = tolerance level for zero ### if (!is.square.matrix( x ) ) stop( "argument x is not a square matrix" ) if ( !is.numeric( x ) ) stop( "argument x is not a numeric matrix" ) y <- x diag( y ) <- rep( 0, nrow( y ) ) return( all( abs( y ) < tol ) ) } r-cran-matrixcalc-1.0.3/R/is.idempotent.matrix.R000077500000000000000000000010761274367517000214560ustar00rootroot00000000000000is.idempotent.matrix <- function( x, tol=1e-8 ) { ### ### This function returns TRUE if the argument matrix is idempotent, ### that is, the product of the matrix with itself returns the same ### matrix within the prescribed tolerance and FALSE otherwise ### ### arguments ### x = a numeric square matrix ### tol = tolerance level for zero ### if (!is.square.matrix( x ) ) stop( "argument x is not a square matrix" ) if ( !is.numeric( x ) ) stop( "argument x is not a numeric matrix" ) return( all( abs( x %*% x - x ) < tol ) ) } r-cran-matrixcalc-1.0.3/R/is.indefinite.R000077500000000000000000000015711274367517000201210ustar00rootroot00000000000000is.indefinite <- function( x, tol=1e-8 ) { ### ### this function determines if the given real symmetric matrix is indefinite, ### that is, the matrix is neither positive definite nor negative definite. ### ### parameters ### x = a square numeric matrix object ### tol = tolerance level for zero ### if ( !is.square.matrix( x ) ) stop( "argument x is not a square matrix" ) if ( !is.symmetric.matrix( x ) ) stop( "argument x is not a symmetric matrix" ) if ( !is.numeric( x ) ) stop( "argument x is not a numeric matrix" ) eigenvalues <- eigen(x, only.values = TRUE)$values n <- nrow( x ) for ( i in 1: n ) { if ( abs( eigenvalues[i] ) < tol ) { eigenvalues[i] <- 0 } } if( any( eigenvalues > 0 ) && any( eigenvalues < 0 ) ) { return( TRUE ) } return( FALSE ) } r-cran-matrixcalc-1.0.3/R/is.negative.definite.R000077500000000000000000000014451274367517000213730ustar00rootroot00000000000000is.negative.definite <- function( x, tol=1e-8 ) { ### ### this function determines if the given real symmetric matrix is negative definite ### ### parameters ### x = a square numeric matrix object ### tol = tolerance level for zero ### if ( !is.square.matrix( x ) ) stop( "argument x is not a square matrix" ) if ( !is.symmetric.matrix( x ) ) stop( "argument x is not a symmetric matrix" ) if ( !is.numeric( x ) ) stop( "argument x is not a numeric matrix" ) eigenvalues <- eigen(x, only.values = TRUE)$values n <- nrow( x ) for ( i in 1: n ) { if ( abs( eigenvalues[i] ) < tol ) { eigenvalues[i] <- 0 } } if ( any( eigenvalues >= 0 ) ) { return( FALSE ) } return( TRUE ) } r-cran-matrixcalc-1.0.3/R/is.negative.semi.definite.R000077500000000000000000000014561274367517000223310ustar00rootroot00000000000000is.negative.semi.definite <- function( x, tol=1e-8 ) { ### ### this function determines if the given real symmetric matrix is negative semi definite ### ### parameters ### x = a square numeric matrix object ### tol = tolerance level for zero ### if ( !is.square.matrix( x ) ) stop( "argument x is not a square matrix" ) if ( !is.symmetric.matrix( x ) ) stop( "argument x is not a symmetric matrix" ) if ( !is.numeric( x ) ) stop( "argument x is not a numeric matrix" ) eigenvalues <- eigen(x, only.values = TRUE)$values n <- nrow( x ) for ( i in 1: n ) { if ( abs( eigenvalues[i] ) < tol ) { eigenvalues[i] <- 0 } } if ( any( eigenvalues > 0 ) ) { return( FALSE ) } return( TRUE ) } r-cran-matrixcalc-1.0.3/R/is.non.singular.matrix.R000077500000000000000000000007441274367517000217240ustar00rootroot00000000000000is.non.singular.matrix <- function( x, tol=1e-8 ) { ### ### This function determines if a square matrix is non singular by ### evaluating the determinant ### ### arguments ### x = a numeric square matrix ### tol = tolerance level for zero ### if (!is.square.matrix( x ) ) stop( "argument x is not a square matrix" ) if ( !is.numeric( x ) ) stop( "argument x is not a numeric matrix" ) det.x <- det( x ) return( abs( det.x ) >= tol ) } r-cran-matrixcalc-1.0.3/R/is.positive.definite.R000077500000000000000000000014451274367517000214330ustar00rootroot00000000000000is.positive.definite <- function( x, tol=1e-8 ) { ### ### this function determines if the given real symmetric matrix is positive definite ### ### parameters ### x = a square numeric matrix object ### tol = tolerance level for zero ### if ( !is.square.matrix( x ) ) stop( "argument x is not a square matrix" ) if ( !is.symmetric.matrix( x ) ) stop( "argument x is not a symmetric matrix" ) if ( !is.numeric( x ) ) stop( "argument x is not a numeric matrix" ) eigenvalues <- eigen(x, only.values = TRUE)$values n <- nrow( x ) for ( i in 1: n ) { if ( abs( eigenvalues[i] ) < tol ) { eigenvalues[i] <- 0 } } if ( any( eigenvalues <= 0 ) ) { return( FALSE ) } return( TRUE ) } r-cran-matrixcalc-1.0.3/R/is.positive.semi.definite.R000077500000000000000000000014511274367517000223640ustar00rootroot00000000000000is.positive.semi.definite <- function( x, tol=1e-8 ) { ### ### this function determines if the given real symmetric matrix is positive semi definite ### parameters ### x = a square numeric matrix object ### tol = tolerance level for zero ### if ( !is.square.matrix( x ) ) stop( "argument x is not a square matrix" ) if ( !is.symmetric.matrix( x ) ) stop( "argument x is not a symmetric matrix" ) if ( !is.numeric( x ) ) stop( "argument x is not a numeric matrix" ) eigenvalues <- eigen(x, only.values = TRUE)$values n <- nrow( x ) for ( i in 1: n ) { if ( abs( eigenvalues[i] ) < tol ) { eigenvalues[i] <- 0 } } if ( any( eigenvalues < 0 ) ) { return( FALSE ) } return( TRUE ) } r-cran-matrixcalc-1.0.3/R/is.singular.matrix.R000077500000000000000000000007301274367517000211260ustar00rootroot00000000000000is.singular.matrix <- function( x, tol=1e-8 ) { ### ### this function returns TRUE if the matrix argument x ### is singular and FALSE otherwise ### ### argument ### x = a numeric square matrix ### tol = tolerance level for zero ### if (!is.square.matrix( x ) ) stop( "argument x is not a square matrix" ) if ( !is.numeric( x ) ) stop( "argument x is not a numeric matrix" ) det.x <- det( x ) return( abs( det.x ) < tol ) } r-cran-matrixcalc-1.0.3/R/is.skew.symmetric.matrix.R000077500000000000000000000007311274367517000222670ustar00rootroot00000000000000is.skew.symmetric.matrix <- function ( x, tol=1e-8 ) { ### ### this function returns TRUE if the matrix argument x is ### skew symmetric and FALSE otherwise ### ### argument ### x = a numeric square matrix ### tol = tolerance level for zero ### if ( !is.square.matrix( x ) ) stop( "argument x is not a square matrix" ) if ( !is.numeric( x ) ) stop( "argument x is not a numeric matrix" ) return( all( abs( x + t(x) ) < tol ) ) } r-cran-matrixcalc-1.0.3/R/is.square.matrix.R000077500000000000000000000004031274367517000205770ustar00rootroot00000000000000is.square.matrix <- function( x ) { ### ### determines if the given matrix is a square matrix ### ### arguments ### x = a matrix object ### if ( !is.matrix( x ) ) stop( "argument x is not a matrix" ) return( nrow(x) == ncol(x) ) } r-cran-matrixcalc-1.0.3/R/is.symmetric.matrix.R000077500000000000000000000007511274367517000213210ustar00rootroot00000000000000is.symmetric.matrix <- function( x ) { ### ### this function determines if the matrix is symmetric ### ### argument ### x = a numeric matrix object ### if ( !is.matrix( x ) ) { stop( "argument x is not a matrix" ) } if ( !is.numeric( x ) ) { stop( "argument x is not a numeric matrix" ) } if ( !is.square.matrix( x ) ) stop( "argument x is not a square numeric matrix" ) return( sum( x == t(x) ) == ( nrow(x) ^ 2 ) ) } r-cran-matrixcalc-1.0.3/R/lower.triangle.R000077500000000000000000000005051274367517000203210ustar00rootroot00000000000000lower.triangle <- function( x ) { ### ### this function returns the lower triangular matrix portion of matrix x ### ### Parameters ### x = a numeric matrix ### if ( !is.square.matrix( x ) ) stop( "argument x is not a square numeric matrix" ) y <- x y[row(x) < col(y)] <- 0 return( y ) } r-cran-matrixcalc-1.0.3/R/lu.decomposition.R000077500000000000000000000026351274367517000206660ustar00rootroot00000000000000lu.decomposition <- function( x ) { ### ### 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 ### ### arguments ### x = a square numeric matrix ### if ( !is.square.matrix( x ) ) stop( "argument x is not a square matrix" ) if ( !is.numeric( x ) ) stop( "argument x is not numeric" ) n <- nrow( x ) L <- matrix( 0, nrow=n, ncol=n ) U <- matrix( 0, nrow=n, ncol=n ) diag( L ) <- rep( 1, n ) for ( i in 1:n ) { ip1 <- i + 1 im1 <- i - 1 for ( j in 1:n ) { U[i,j] <- x[i,j] if ( im1 > 0 ) { for ( k in 1:im1 ) { U[i,j] <- U[i,j] - L[i,k] * U[k,j] } } } if ( ip1 <= n ) { for ( j in ip1:n ) { L[j,i] <- x[j,i] if ( im1 > 0 ) { for ( k in 1:im1 ) { L[j,i] <- L[j,i] - L[j,k] * U[k,i] } } if ( U[i,i] == 0 ) stop( "argument x is a singular matrix" ) L[j,i] <- L[j,i] / U[i,i] } } } result <- list( L=L, U=U ) return( result ) } r-cran-matrixcalc-1.0.3/R/matrix.inverse.R000077500000000000000000000004231274367517000203420ustar00rootroot00000000000000matrix.inverse <- function( x ) { ### ### this function returns the inverse of a square matrix ### ### Parameters ### x = a square numeric matrix ### if ( !is.square.matrix( x ) ) stop( "argument x is not a square matrix" ) return( solve( x ) ) } r-cran-matrixcalc-1.0.3/R/matrix.power.R000077500000000000000000000020601274367517000200220ustar00rootroot00000000000000matrix.power <- function( x, k ) { ### ### 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 ### ### arguments ### x = a numeric square matrix ### k = an integer value exponent ### if ( !is.square.matrix( x ) ) stop( "argument x is not a square matrix" ) if ( !is.numeric( x ) ) stop( "argument x is not numeric" ) if ( !is.numeric( k ) ) stop( "argument k is not numeric" ) if ( !is.vector( k ) ) stop( "argument k is not the proper data type" ) if ( length( k ) > 1 ) stop( "argument k is not a scalr number" ) if ( k != trunc( k ) ) stop( "argument k is not an integer" ) n <- nrow( x ) if ( k == 0 ) { return( diag( 1, n ) ) } if ( k < 0 ) { return( matrix.power( matrix.inverse(x), -k ) ) } x.k <- x i <- 2 while ( i <= k ) { x.k <- x.k %*% x i <- i + 1 } return( x.k ) } r-cran-matrixcalc-1.0.3/R/matrix.rank.R000077500000000000000000000010521274367517000176210ustar00rootroot00000000000000matrix.rank <- function ( x, method=c("qr", "chol" ) ) { ### ### this function returns the rank of a square matrix based on the selected method ### ### Parameter ### x = a square numeric matrix ### method = a character string that defines the method ### if ( !is.square.matrix( x ) ) stop( "argument x is not a square matrix" ) method = method[1] if (method == "chol") { ans = attr(chol(x, pivot = TRUE), "rank") } else { ans = qr(x)$rank } # Return Value: return( ans ) } r-cran-matrixcalc-1.0.3/R/matrix.trace.R000077500000000000000000000004441274367517000177700ustar00rootroot00000000000000matrix.trace <- function( x ) { ### ### this function returns the trace of the given square matrix ### ### parameters ### x = a numeric square matrix object ### if ( !is.square.matrix( x ) ) stop( "argument x is not a square matrix" ) return( sum( diag( x ) ) ) } r-cran-matrixcalc-1.0.3/R/maximum.norm.R000077500000000000000000000010351274367517000200130ustar00rootroot00000000000000maximum.norm <- function( x ) { ### ### This function computes and returns the maximum norm of matrix x ### ### arguments ### x = a numeric matrix or vector ### if ( !is.numeric( x ) ) { stop( "argument x is not numeric" ) } if ( is.matrix( x ) ) { Xmat <- x } else { if ( is.vector( x ) ) { X.mat <- x } else { stop( "argument is neither a matrix nor a vector" ) } } norm <- max( abs( Xmat ) ) return( norm ) } r-cran-matrixcalc-1.0.3/R/one.norm.R000077500000000000000000000011561274367517000171230ustar00rootroot00000000000000one.norm <- function( x ) { ### ### This function returns the p = 1 norm wich is the maximum absolute column sum ### of the matrix x ### ### argument ### x = a numeric vector or matrix ### if ( !is.numeric( x ) ) { stop( "argument x is not numeric" ) } if ( is.matrix( x ) ) { Xmat <- x } else { if ( is.vector( x ) ) { Xmat <- matrix( x, nrow=length(x), ncol=1 ) } else { stop( "argument x is neither a matrix nor a vector" ) } } norm <- max( apply( abs( Xmat ), 2, sum ) ) return( norm ) } r-cran-matrixcalc-1.0.3/R/pascal.matrix.R000077500000000000000000000004241274367517000201330ustar00rootroot00000000000000pascal.matrix <- function( n ) { ### ### this function returns an n by n Pascal matrix ### ### Parameter ### n = the row( column ) dimension of the matrix ### S <- symmetric.pascal.matrix( n ) luS <- lu.decomposition( S ) P <- luS$L return( P ) } r-cran-matrixcalc-1.0.3/R/s.R000077500000000000000000000004351274367517000156310ustar00rootroot00000000000000"%s%" <- function( x, y ) { ### ### This function is a wrapper the direct sum of two vectors or ### matrices resulting in a block diagonal matrix ### ### Arguments ### x = a numeric matrix or vector ### y = a numeric matrix or vector ### return( direct.sum( x, y ) ) } r-cran-matrixcalc-1.0.3/R/set.submatrix.R000077500000000000000000000025121274367517000201750ustar00rootroot00000000000000set.submatrix <- function( x, y, row, col ) { ### ### Returns a matrix where y has been inserted into x at the given row and column ### ### Arguments ### x = a matrix object ### y = a matrix object ### row = an integer row number ### col = an integer column number ### if ( !is.matrix( x ) ) stop( "argument x is not a matrix" ) if ( !is.numeric( x ) ) stop( "argument x is not a numeric matrix" ) if ( !is.matrix( y ) ) stop( "argument y is not a matrix" ) if ( !is.numeric( y ) ) stop( "argument y is not a numeric matrix" ) if ( row <= 0 ) stop( "argument row is not positive" ) if ( row != trunc( row ) ) stop( "argument row is not an integer" ) if ( col <= 0 ) stop( "argument col is not positive" ) if ( col != trunc( col ) ) stop( "argument col is not an integer" ) row.range <- row:(row+nrow(y)-1) col.range <- col:(col+ncol(y)-1) x.row.range <- 1:nrow(x) x.col.range <- 1:ncol(x) if ( sum( row.range %in% x.row.range ) != length(row.range) ) stop( "row range not inside row of argument x" ) if ( sum( col.range %in% x.col.range ) != length(col.range) ) stop( "col range not inside the column of argument x" ) z <- x z[row.range,col.range] <- y return( z ) } r-cran-matrixcalc-1.0.3/R/shift.down.R000077500000000000000000000016241274367517000174530ustar00rootroot00000000000000shift.down <- function( A, rows = 1, fill = 0 ) { ### ### this function returns a matrix that has been shifted down m rows ### filling the previous rows with the given fill value ### ### Arguments ### A = a numerical matrix ### rows = number of rows to be shifed downwards ### fill = a numeric value to be used to fill the rows ### if ( !is.matrix( A ) ) { stop( "argument A is not a matrix" ) } if ( !is.numeric( A ) ) { stop( "argument A is not a numeric matrix" ) } if ( rows < 0 ) stop( "Argument rows is not positive" ) if ( rows != trunc( rows ) ) stop( "Arguments rows is not an integer" ) if ( !is.numeric( fill ) ) stop( "Argument fill is not numeric" ) if ( rows > 0 ) return( shift.down( rbind( rep( fill, ncol(A) ), A[1:nrow(A)-1,] ), rows - 1, fill ) ) return( A ) } r-cran-matrixcalc-1.0.3/R/shift.left.R000077500000000000000000000016311274367517000174340ustar00rootroot00000000000000shift.left <- function( A, cols = 1, fill = 0 ) { ### ### this function returns a matrix that has been shifted left m cols ### filling the subsequent columns with the given fill value ### ### Arguments ### A = a numerical matrix ### cols = number of cols to be shifed to the left ### fill = a numeric value to be used to fill the cols ### if ( !is.matrix( A ) ) { stop( "argument A is not a matrix" ) } if ( !is.numeric( A ) ) { stop( "argument A is not a numeric matrix" ) } if ( cols != trunc( cols ) ) stop( "Arguments cols is not an integer" ) if ( cols < 0 ) stop( "Argument cols is not positive" ) if ( !is.numeric( fill ) ) stop( "Argument fill is not numeric" ) if ( cols > 0 ) return( shift.left( cbind( A[,2:ncol(A)], rep( fill, nrow(A) ) ), cols - 1, fill ) ) return( A ) } r-cran-matrixcalc-1.0.3/R/shift.right.R000077500000000000000000000016471274367517000176260ustar00rootroot00000000000000shift.right <- function( A, cols = 1, fill = 0 ) { ### ### this function returns a matrix that has been shifted to the right m columns ### filling the previous columns with the given fill value ### ### Arguments ### A = a numerical matrix ### cols = number of cols to be shifed to the right ### fill = a numeric value to be used to fill the cols ### if ( !is.matrix( A ) ) { stop( "argument A is not a matrix" ) } if ( !is.numeric( A ) ) { stop( "argument A is not a numeric matrix" ) } if ( cols < 0 ) stop( "Argument cols is not positive" ) if ( cols != trunc( cols ) ) stop( "Arguments cols is not an integer" ) if ( !is.numeric( fill ) ) stop( "Argument fill is not numeric" ) if ( cols > 0 ) return( shift.right( cbind( rep( fill, nrow(A) ), A[,1:ncol(A)-1] ), cols - 1, fill ) ) return( A ) } r-cran-matrixcalc-1.0.3/R/shift.up.R000077500000000000000000000016121274367517000171250ustar00rootroot00000000000000shift.up <- function( A, rows = 1, fill = 0 ) { ### ### this function returns a matrix that has been shifted up m rows ### filling the previous rows with the given fill value ### ### Arguments ### A = a numerical matrix ### rows = number of rows to be shifed upwards ### fill = a numeric value to be used to fill the rows ### if ( !is.matrix( A ) ) { stop( "argument A is not a matrix" ) } if ( !is.numeric( A ) ) { stop( "argument A is not a numeric matrix" ) } if ( rows != trunc( rows ) ) stop( "Arguments rows is not an integer" ) if ( rows < 0 ) stop( "Argument rows is not positive" ) if ( !is.numeric( fill ) ) stop( "Argument fill is not numeric" ) if ( rows > 0 ) return( shift.up( rbind( A[2:nrow(A),], rep( fill, ncol(A) ) ), rows - 1, fill ) ) return( A ) } r-cran-matrixcalc-1.0.3/R/spectral.norm.R000077500000000000000000000012711274367517000201550ustar00rootroot00000000000000spectral.norm <- function( x ) { ### ### This function computes the spectral norm for an m by n matrix x ### If x is a vector, then the L2 norm is returned ### ### arguments ### x = a numeric matrix or vector ### if ( !is.numeric( x ) ) { stop( "argument x is not numeric" ) } if ( is.vector( x ) ) { return( sqrt( sum( x * x ) ) ) } if ( !is.matrix( x ) ) { return( "argument x is not a matrix" ) } A <- t(x) %*% x eigenA <- eigen( A ) lambdaA <- eigenA$values maxLambdaA <- lambdaA[1] if ( maxLambdaA < 0 ) { stop( "t(x) %*% x is negative definite" ) } return( sqrt( maxLambdaA ) ) } r-cran-matrixcalc-1.0.3/R/stirling.matrix.R000077500000000000000000000020621274367517000205230ustar00rootroot00000000000000stirling.matrix <- function( n ) { ### ### this function constructs the Stirling matrix, a lower triangular matrix containing ### the Stirling numbers of the second kind ### ### argument ### n = a positive integer for the order of the matrix ### if ( !is.numeric( n ) ) stop( "argument n is not numeric" ) if ( !is.vector( n ) ) stop( "argument n is not of the proper data type" ) if ( length( n ) != 1 ) stop( "argument n is not a scalar integer" ) if ( n < 1 ) stop( "arguemtn n is less than 1" ) if ( n == 1 ) { return( S ) } nm1 <- n - 1 np1 <- n + 1 S <- matrix( 0, nrow=np1, ncol=np1 ) for ( i in 0:n ) { ii <- i + 1 S[ii,ii] <- 1 } for ( j in 0:n ) { jj <- j + 1 S[1,jj] <- 0 S[jj,1] <- 0 } for ( i in 1:nm1 ) { ii <- i + 1 for ( j in 1:i ) { jj <- j + 1 S[ii+1,jj] <- S[ii,jj-1] + j * S[ii,jj] } } S[1,1] <- 1 return( S ) } r-cran-matrixcalc-1.0.3/R/svd.inverse.R000077500000000000000000000022551274367517000176370ustar00rootroot00000000000000svd.inverse <- function( x ) { ### ### This function returns the Penrose-Moore pseudo inverse matrix ### for the given n by p matrix A using singular value decomposition ### ### arguments ### x = a numeric matrix or vector ### nu = positive integer for the number of left singular vectors to be computed ### nv = positive integer for the number of right singular vectors to be computed ### LINKPAC = logical value to determine if LINKPACK should be used. ### if ( !is.numeric( x ) ) { stop( "argument x is not numeric" ) } if ( is.matrix( x ) ) { Xmat <- x } else { if ( is.vector( x ) ) { Xmat <- matrix( x, nrow=length( x ), ncol=1 ) } else { stop( "argument x is neither a vector nor a matrix" ) } } svdXmat <- svd( Xmat ) U <- svdXmat$u d <- svdXmat$d if ( any( d == 0 ) ) { stop( "x has at least one zero singular value" ) } if ( length( d ) == 1 ) { Dinv <- matrix( 1 / d, nrow=1 ) } else { Dinv <- diag( 1 / d ) } V <- svdXmat$v Xinv <- V %*% Dinv %*% t( U ) return( Xinv ) } r-cran-matrixcalc-1.0.3/R/symmetric.pascal.matrix.R000077500000000000000000000011461274367517000221500ustar00rootroot00000000000000symmetric.pascal.matrix <- function( n ) { ### ### this function returns an n by n Pascal matrix ### ### Parameter ### n = the row( column ) dimension of the matrix ### if ( n <= 0 ) stop( "argument n is not positive" ) if ( n != trunc( n ) ) stop( "argument n is not an integer" ) nm1 = n-1 n.over.r <- function(n, r) { prod(1:n) / (prod(1:(n-r)) * prod(1:r) ) } X <- rep(1, nm1) for ( i in 1:nm1 ) for ( j in 1:nm1 ) X <- c(X, n.over.r(i+j, j)) X <- cbind(rep(1, nm1+1), matrix(X, byrow = TRUE, ncol = nm1)) return( X ) } r-cran-matrixcalc-1.0.3/R/toeplitz.matrix.R000077500000000000000000000015401274367517000205420ustar00rootroot00000000000000toeplitz.matrix <- function( n, x ) { ### ### this function returns the order n Toeplitz matrix derived from ### the order 2 * n - 1 vector ### ### arguments ### n = a positive integer value for the order of the Hankel matrix ### x = an order 2 * n - 1 vector of numeric values ### if ( !is.numeric( n ) ) stop( "argument n is not numeric" ) if ( n != trunc( n ) ) stop( "argument n ix not an integer" ) if ( n < 2 ) stop( "argument n is less than 2" ) if ( !is.vector( x ) ) stop( "argument x is not a vector" ) m <- length( x ) if ( m != ( 2 * n - 1 )) stop( "length of argument x is not comparable with n n" ) T <- matrix( 0, nrow=n, ncol=n ) for ( i in 1:n ) { for ( j in 1:n ) { T[i,j] <- x[(i - j) + n] } } return( T ) } r-cran-matrixcalc-1.0.3/R/u.vectors.R000077500000000000000000000014621274367517000173200ustar00rootroot00000000000000u.vectors <- function( n ) { ### ### This function constructs an identity matrix I of order ### p = n * ( n +1 ) / 2. It also builds a lower triangular square matrix of ### order n. The value of element [i,j] is the column number ### in the identify matrix. It is the mapping from the coordinates ### to the column vector in the identity matrix. ### ### argument ### n = a positive integer value ### if ( n != trunc( n ) ) stop( "argument n is not an integer" ) if ( n < 2 ) stop( "argument n is less than 2" ) p <- n * ( n + 1 ) / 2 I <- diag( rep( 1, p ) ) k <- matrix( 0, nrow=n, ncol=n ) for ( j in 1:n ) { for ( i in j:n ) { k[i,j] <- ( j - 1 ) * n + i - 0.5 * j * ( j - 1 ) } } return( list( k=k, I=I ) ) } r-cran-matrixcalc-1.0.3/R/upper.triangle.R000077500000000000000000000005051274367517000203240ustar00rootroot00000000000000upper.triangle <- function( x ) { ### ### this function returns the lower triangular matrix portion of matrix x ### ### Parameters ### x = a numeric matrix ### if ( !is.square.matrix( x ) ) stop( "argument x is not a square numeric matrix" ) y <- x y[row(x) > col(y)] <- 0 return( y ) } r-cran-matrixcalc-1.0.3/R/vandermonde.matrix.R000077500000000000000000000011321274367517000211670ustar00rootroot00000000000000vandermonde.matrix <- function( alpha, n ) { ### ### this function returns an m by n matrix of the powers of the alpha vector ### ### Parameters ### alpha = an m dimensional vector ### n = an integer ### if ( !is.vector( alpha ) ) stop( "argument alpha is not a vector" ) if ( !is.numeric( alpha ) ) stop( "argument n is not a numeric vector" ) m <- length( alpha ) V <- matrix( 0, nrow=m, ncol=n ) V[,1] <- rep( 1, m ) j <- 2 while ( j <= n ) { x <- alpha ^ ( j - 1 ) V[,j] <- x j <- j + 1 } return( V ) } r-cran-matrixcalc-1.0.3/R/vec.R000077500000000000000000000005771274367517000161530ustar00rootroot00000000000000vec <- function( x ) { ### ### this function returns a column vector that is a stack of the columns of x ### ### Parameters ### x = a numeric matrix ### if ( !is.matrix( x ) ) { stop( "argument x is not a matrix" ) } if ( !is.numeric( x ) ) { stop( "argument x is not a numeric matrix" ) } return( t( t( as.vector( x ) ) ) ) } r-cran-matrixcalc-1.0.3/R/vech.R000077500000000000000000000004741274367517000163170ustar00rootroot00000000000000vech <- function( x ) { ### ### returns a stack of the lower triangular matrix as a matrix with 1 column ### ### Parameters ### x = a numeric matrix square matrix ### if ( !is.square.matrix( x ) ) stop( "argument x is not a square numeric matrix" ) return( t( t( x[!upper.tri(x)] ) ) ) } r-cran-matrixcalc-1.0.3/man/000077500000000000000000000000001274367517000156115ustar00rootroot00000000000000r-cran-matrixcalc-1.0.3/man/D.matrix.Rd000077500000000000000000000034661274367517000176020ustar00rootroot00000000000000\name{D.matrix} \alias{D.matrix} \title{ Duplication matrix } \description{ This function constructs the linear transformation D that maps vech(A) to vec(A) when A is a symmetric matrix } \usage{ D.matrix(n) } \arguments{ \item{n}{ a positive integer value for the order of the underlying matrix } } \details{ Let \eqn{{\bf{T}}_{i,j}} be an \eqn{n \times n} matrix with 1 in its \eqn{\left( {i,j} \right)} element \eqn{1 \le i,j \le n}. and zeroes elsewhere. These matrices are constructed by the function \code{T.matrices}. The formula for the transpose of matrix \eqn{\bf{D}} is \eqn{{\bf{D'}} = \sum\limits_{j = 1}^n {\sum\limits_{i = j}^n {{{\bf{u}}_{i,j}}\;{{\left( {vec\;{{\bf{T}}_{i,j}}} \right)}^\prime }} } } where \eqn{{{{\bf{u}}_{i,j}}}} is the column vector in the order \eqn{\frac{1}{2}n\left( {n + 1} \right)} identity matrix for column \eqn{k = \left( {j - 1} \right)n + i - \frac{1}{2}j\left( {j - 1} \right)}. The function \code{u.vectors} generates these vectors. } \value{ It returns an \eqn{{n^2}\; \times \;\frac{1}{2}n\left( {n + 1} \right)} matrix. } \references{ Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, \emph{SIAM Journal on Algebraic Discrete Methods}, 1(4), December 1980, 422-449. Magnus, J. R. and H. Neudecker (1999). \emph{Matrix Differential Calculus with Applications in Statistics and Econometrics}, Second Edition, John Wiley. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{T.matrices}}, \code{\link{u.vectors}} } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/E.matrices.Rd000077500000000000000000000033531274367517000201010ustar00rootroot00000000000000\name{E.matrices} \alias{E.matrices} \title{ List of E Matrices } \description{ 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. } \usage{ E.matrices(n) } \arguments{ \item{n}{ a positive integer for the order of the identity matrix } } \details{ Let \eqn{{{\bf{I}}_n} = \left[ {\begin{array}{*{20}{c}} {{{\bf{e}}_1}}&{{{\bf{e}}_2}}& \cdots &{{{\bf{e}}_n}} \end{array}} \right]} be the order \eqn{n} identity matrix with corresponding unit vectors \eqn{{{{\bf{e}}_i}}} with one in its \eqn{i}th position and zeros elsewhere. The \eqn{n \times n} matrix \eqn{{{\bf{E}}_{i,j}}} is computed from the unit vectors \eqn{{{{\bf{e}}_i}}} and \eqn{{{{\bf{e}}_j}}} as \eqn{{{\bf{E}}_{i,j}} = {{\bf{e}}_i}\;{{\bf{e'}}_j}}. These matrices are stored as components in a list of lists. } \value{ A list with \eqn{n} components \item{1 }{A sublist of \eqn{n} components} \item{2 }{A sublist of \eqn{n} components} ... \item{n }{A sublist of \eqn{n} components} Each component \eqn{j} of sublist \eqn{i} is a matrix \eqn{{\bf{E}}_{i,j}} } \references{ Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, \emph{SIAM Journal on Algebraic Discrete Methods}, 1(4), December 1980, 422-449. Magnus, J. R. and H. Neudecker (1999). \emph{Matrix Differential Calculus with Applications in Statistics and Econometrics}, Second Edition, John Wiley. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ The argument n must be an integer value greater than or equal to 2. } \examples{ E <- E.matrices( 3 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/H.matrices.Rd000077500000000000000000000037611274367517000201070ustar00rootroot00000000000000\name{H.matrices} \alias{H.matrices} \title{ List of H Matrices } \description{ 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. } \usage{ H.matrices(r, c = r) } \arguments{ \item{r}{ a positive integer value for an order r identity matrix } \item{c}{ a positive integer value for an order c identify matrix } } \details{ Let \eqn{{{\bf{I}}_r} = \left[ {\begin{array}{*{20}{c}} {{{\bf{a}}_1}}&{{{\bf{a}}_2}}& \cdots &{{{\bf{a}}_r}} \end{array}} \right]} be the order \eqn{r} identity matrix with corresponding unit vectors \eqn{{{{\bf{a}}_i}}} with one in its \eqn{i}th position and zeros elsewhere. Let \eqn{{{\bf{I}}_c} = \left[ {\begin{array}{*{20}{c}} {{{\bf{b}}_1}}&{{{\bf{b}}_2}}& \cdots &{{{\bf{b}}_c}} \end{array}} \right]} be the order \eqn{c} identity matrix with corresponding unit vectors \eqn{{{{\bf{b}}_i}}} with one in its \eqn{i}th position and zeros elsewhere. The \eqn{r \times c} matrix \eqn{{\bf{H}}{}_{i,j} = {{\bf{a}}_i}\;{{\bf{b'}}_j}} is used in the computation of the commutation matrix. } \value{ A list with \eqn{r} components \item{1 }{A sublist of \eqn{c} components} \item{2 }{A sublist of \eqn{c} components} ... \item{r }{A sublist of c components} Each component \eqn{j} of sublist \eqn{i} is a matrix \eqn{{\bf{H}}_{i,j}} } \references{ Magnus, J. R. and H. Neudecker (1979). The commutation matrix: some properties and applications, \emph{The Annals of Statistics}, 7(2), 381-394. Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, \emph{SIAM Journal on Algebraic Discrete Methods}, 1(4), December 1980, 422-449. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ The argument n must be an integer value greater than or equal to two. } \examples{ H.2.3 <- H.matrices( 2, 3 ) H.3 <- H.matrices( 3 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/K.matrix.Rd000077500000000000000000000031411274367517000175770ustar00rootroot00000000000000\name{K.matrix} \alias{K.matrix} \title{ K Matrix } \description{ 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. } \usage{ K.matrix(r, c = r) } \arguments{ \item{r}{ a positive integer row dimension } \item{c}{ a positive integer column dimension } } \details{ The \eqn{r \times c} matrices \eqn{{\bf{H}}{}_{i,j}} constructed by the function \code{H.matrices} are combined using direct product to generate the commutation product with the formula \eqn{{{\bf{K}}_{r,c}} = \sum\limits_{i = 1}^r {\sum\limits_{j = 1}^c {\left( {{{\bf{H}}_{i,j}} \otimes {{{\bf{H'}}}_{i,j}}} \right)} }} } \value{ An order \eqn{\left( {r\;c} \right)} matrix. } \references{ Magnus, J. R. and H. Neudecker (1979). The commutation matrix: some properties and applications, \emph{The Annals of Statistics}, 7(2), 381-394. Magnus, J. R. and H. Neudecker (1999) \emph{Matrix Differential Calculus with Applications in Statistics and Econometrics}, Second Edition, John Wiley. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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 } \seealso{ \code{\link{H.matrices}} } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/L.matrix.Rd000077500000000000000000000034371274367517000176100ustar00rootroot00000000000000\name{L.matrix} \alias{L.matrix} \title{ Construct L Matrix } \description{ 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) } \usage{ L.matrix(n) } \arguments{ \item{n}{ a positive integer order for the associated matrix A } } \details{ The formula used to compute the L matrix which is also called the elimination matrix is \eqn{{\bf{L}} = \sum\limits_{j = 1}^n {\sum\limits_{i = j}^n {{{\bf{u}}_{i,j}}{{\left( {vec\;{{\bf{E}}_{i,j}}} \right)}^\prime }} } } \eqn{{{{\bf{u}}_{i,j}}}} are the \eqn{n \times 1} vectors constructed by the function \code{u.vectors}. \eqn{{{{\bf{E}}_{i,j}}}} are the \eqn{ n \times n} matrices constructed by the function \code{E.matrices}. } \value{ An \eqn{\left[ {\frac{1}{2}n\left( {n + 1} \right)} \right] \times {n^2}} matrix. } \references{ Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, \emph{SIAM Journal on Algebraic Discrete Methods}, 1(4), December 1980, 422-449. Magnus, J. R. and H. Neudecker (1999) \emph{Matrix Differential Calculus with Applications in Statistics and Econometrics}, Second Edition, John Wiley. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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. } \seealso{ \code{\link{elimination.matrix}}, \code{\link{E.matrices}}, \code{\link{u.vectors}}, } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/N.matrix.Rd000077500000000000000000000025311274367517000176040ustar00rootroot00000000000000\name{N.matrix} \alias{N.matrix} \title{ Construct N Matrix } \description{ 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 } \usage{ N.matrix(n) } \arguments{ \item{n}{ A positive integer matrix order } } \details{ Let \eqn{{\bf{K}_n}} be the order \eqn{n} implicit commutation matrix (i.e., \eqn{{{\bf{K}}_{n,n}}} ). and \eqn{{{\bf{I}}_n}} the order \eqn{n} identity matrix. The formula for the matrix is \eqn{{\bf{N}} = \frac{1}{2}\left( {{{\bf{K}}_n} + {{\bf{I}}_n}} \right)}. } \value{ An order \eqn{n} matrix. } \references{ Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, \emph{SIAM Journal on Algebraic Discrete Methods}, 1(4), December 1980, 422-449. Magnus, J. R. and H. Neudecker (1999) \emph{Matrix Differential Calculus with Applications in Statistics and Econometrics}, Second Edition, John Wiley. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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. } \seealso{ \code{\link{K.matrix}} } \examples{ N <- N.matrix( 3 ) print( N ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/T.matrices.Rd000077500000000000000000000032211274367517000201120ustar00rootroot00000000000000\name{T.matrices} \alias{T.matrices} \title{ List of T Matrices } \description{ 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. } \usage{ T.matrices(n) } \arguments{ \item{n}{ a positive integer value for the order of the matrices } } \details{ Let \eqn{{{\bf{E}}_{i,j}}\;i = 1, \ldots ,n\;;\;j = 1, \ldots ,n} be a representative order \eqn{n} matrix created with function \code{E.matrices}. The order \eqn{n} matrix \eqn{{{\bf{T}}_{i,j}}} is defined as follows \eqn{{{\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.} } \value{ A list of \eqn{n} components. \item{1 }{A list of \eqn{n} components} \item{2 }{A list of \eqn{n} components} ... \item{n }{A list of \eqn{n} components} Each component \eqn{j} of sublist \eqn{i} is a matrix \eqn{{\bf{T}}_{i,j}} } \references{ Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, \emph{SIAM Journal on Algebraic Discrete Methods}, 1(4), December 1980, 422-449. Magnus, J. R. and H. Neudecker (1999) \emph{Matrix Differential Calculus with Applications in Statistics and Econometrics}, Second Edition, John Wiley. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ The argument n must be an integer value greater than or equal to 2. } \seealso{ \code{\link{E.matrices}} } \examples{ T <- T.matrices( 3 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/commutation.matrix.Rd000077500000000000000000000035001274367517000217430ustar00rootroot00000000000000\name{commutation.matrix} \alias{commutation.matrix} \title{ Commutation matrix for r by c numeric matrices } \description{ 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. } \usage{ commutation.matrix(r, c=r) } \arguments{ \item{r}{ a positive integer integer row dimension } \item{c}{ a positive integer integer column dimension } } \details{ This function is a wrapper function that uses the function \code{K.matrix} to do the actual work. The \eqn{r \times c} matrices \eqn{{\bf{H}}{}_{i,j}} constructed by the function \code{H.matrices} are combined using direct product to generate the commutation product with the following formula \eqn{{{\bf{K}}_{r,c}} = \sum\limits_{i = 1}^r {\sum\limits_{j = 1}^c {\left( {{{\bf{H}}_{i,j}} \otimes {{{\bf{H'}}}_{i,j}}} \right)} }} } \value{ An order \eqn{\left( {r\;c} \right)} matrix. } \references{ Magnus, J. R. and H. Neudecker (1979). The commutation matrix: some properties and applications, \emph{The Annals of Statistics}, 7(2), 381-394. Magnus, J. R. and H. Neudecker (1999) \emph{Matrix Differential Calculus with Applications in Statistics and Econometrics}, Second Edition, John Wiley. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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 } \seealso{ \code{\link{H.matrices}}, \code{\link{K.matrix}} } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/creation.matrix.Rd000077500000000000000000000025231274367517000212140ustar00rootroot00000000000000\name{creation.matrix} \alias{creation.matrix} \title{ Creation Matrix } \description{ 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. } \usage{ creation.matrix(n) } \arguments{ \item{n}{ a positive integer greater than 1 } } \details{ The order \eqn{n} 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 \eqn{\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]}. } \value{ An order \eqn{n} matrix. } \references{ Aceto, L. and D. Trigiante (2001). Matrices of Pascal and Other Greats, \emph{American Mathematical Monthly}, March 2001, 108(3), 232-245. Weinberg, S. (1995). \emph{The Quantum Theory of Fields}, Cambridge University Press. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ If the argument n is not an integer that is greater than 1, the function presents an error message and stops. } \examples{ H <- creation.matrix( 10 ) print( H ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/direct.prod.Rd000077500000000000000000000025451274367517000203260ustar00rootroot00000000000000\name{direct.prod} \alias{direct.prod} \title{ Direct prod of two arrays } \description{ This function computes the direct product of two arrays. The arrays can be numerical vectors or matrices. The result is a matrix. } \usage{ direct.prod( x, y ) } \arguments{ \item{x}{ a numeric matrix or vector } \item{y}{ a numeric matrix or vector } } \details{ If either \eqn{\bf{x}} or \eqn{\bf{y}} is a vector, it is converted to a matrix. Suppose that \eqn{\bf{x}} is an \eqn{m \times n} matrix and \eqn{\bf{y}} is an \eqn{ p \times q} matrix. Then, the function returns the matrix \eqn{\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]}. } \value{ A numeric matrix. } \references{ Magnus, J. R. and H. Neudecker (1999) \emph{Matrix Differential Calculus with Applications in Statistics and Econometrics}, Second Edition, John Wiley. } \author{ Frederick Novomestky \email{fnovomes@poly.edu}, Kurt Hornik \email{Kurt.Hornik@wu-wien.ac.at} } \examples{ x <- matrix( seq( 1, 4 ) ) y <- matrix( seq( 5, 8 ) ) print( direct.prod( x, y ) ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/direct.sum.Rd000077500000000000000000000020361274367517000201610ustar00rootroot00000000000000\name{direct.sum} \alias{direct.sum} \title{ Direct sum of two arrays } \description{ This function computes the direct sum of two arrays. The arrays can be numerical vectors or matrices. The result ia the block diagonal matrix. } \usage{ direct.sum( x, y ) } \arguments{ \item{x}{ a numeric matrix or vector } \item{y}{ a numeric matrix or vector } } \value{ A numeric matrix. } \details{ If either \eqn{\bf{x}} or y is a vector, it is converted to a matrix. The result is a block diagonal matrix \eqn{\left[ {\begin{array}{*{20}c} {\bf{x}} & {\bf{0}} \\ {\bf{0}} & {\bf{y}} \\ \end{array}} \right]}. } \references{ Magnus, J. R. and H. Neudecker (1999) \emph{Matrix Differential Calculus with Applications in Statistics and Econometrics}, Second Edition, John Wiley. } \author{ Frederick Novomestky \email{fnovomes@poly.edu}, Kurt Hornik \email{Kurt.Hornik@wu-wien.ac.at} } \examples{ x <- matrix( seq( 1, 4 ) ) y <- matrix( seq( 5, 8 ) ) print( direct.sum( x, y ) ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/duplication.matrix.Rd000077500000000000000000000037741274367517000217340ustar00rootroot00000000000000\name{duplication.matrix} \alias{duplication.matrix} \title{ Duplication matrix for n by n matrices } \description{ 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. } \usage{ duplication.matrix(n=1) } \arguments{ \item{n}{ Row and column dimension } } \details{ This function is a wrapper function for the function \code{D.matrix}. Let \eqn{{\bf{T}}_{i,j}} be an \eqn{n \times n} matrix with 1 in its \eqn{\left( {i,j} \right)} element \eqn{1 \le i,j \le n}. and zeroes elsewhere. These matrices are constructed by the function \code{T.matrices}. The formula for the transpose of matrix \eqn{\bf{D}} is \eqn{{\bf{D'}} = \sum\limits_{j = 1}^n {\sum\limits_{i = j}^n {{{\bf{u}}_{i,j}}\;{{\left( {vec\;{{\bf{T}}_{i,j}}} \right)}^\prime }} } } where \eqn{{{{\bf{u}}_{i,j}}}} is the column vector in the order \eqn{\frac{1}{2}n\left( {n + 1} \right)} identity matrix for column \eqn{k = \left( {j - 1} \right)n + i - \frac{1}{2}j\left( {j - 1} \right)}. The function \code{u.vectors} generates these vectors. } \value{ It returns an \eqn{{n^2}\; \times \;\frac{1}{2}n\left( {n + 1} \right)} matrix. } \references{ Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, \emph{SIAM Journal on Algebraic Discrete Methods}, 1(4), December 1980, 422-449. Magnus, J. R. and H. Neudecker (1999) \emph{Matrix Differential Calculus with Applications in Statistics and Econometrics}, Second Edition, John Wiley. } \author{ Frederick Novomestky \email{fnovomes@poly.edu}, Kurt Hornik \email{Kurt.Hornik@wu-wien.ac.at} } \seealso{ \code{\link{D.matrix}}, \code{\link{vec}}, \code{\link{vech}} } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/elimination.matrix.Rd000077500000000000000000000036331274367517000217230ustar00rootroot00000000000000\name{elimination.matrix} \alias{elimination.matrix} \title{ Elimination matrix for lower triangular matrices } \description{ 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) } \usage{ elimination.matrix(n) } \arguments{ \item{n}{ row or column dimension } } \details{ This function is a wrapper function to the function \code{L.matrix}. The formula used to compute the L matrix which is also called the elimination matrix is \eqn{{\bf{L}} = \sum\limits_{j = 1}^n {\sum\limits_{i = j}^n {{{\bf{u}}_{i,j}}{{\left( {vec\;{{\bf{E}}_{i,j}}} \right)}^\prime }} } } \eqn{{{{\bf{u}}_{i,j}}}} are the order \eqn{n\left( {n + 1} \right)/2} vectors constructed by the function \code{u.vectors}. \eqn{{{{\bf{E}}_{i,j}}}} are the \eqn{ n \times n} matrices constructed by the function \code{E.matrices}. } \value{ An \eqn{\left[ {\frac{1}{2}n\left( {n + 1} \right)} \right] \times {n^2}} matrix. } \references{ Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, \emph{SIAM Journal on Algebraic Discrete Methods}, 1(4), December 1980, 422-449. Magnus, J. R. and H. Neudecker (1999) \emph{Matrix Differential Calculus with Applications in Statistics and Econometrics}, Second Edition, John Wiley. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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. } \seealso{ \code{\link{E.matrices}}, \code{\link{L.matrix}}, \code{\link{u.vectors}} } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/entrywise.norm.Rd000077500000000000000000000031731274367517000211120ustar00rootroot00000000000000\name{entrywise.norm} \alias{entrywise.norm} \title{ Compute the entrywise norm of a matrix } \description{ This function returns the \eqn{\left\| {\bf{x}} \right\|_p } norm of the matrix \eqn{{\mathbf{x}}}. } \usage{ entrywise.norm(x,p) } \arguments{ \item{x}{ a numeric vector or matrix } \item{p}{ a real value for the power } } \details{ Let \eqn{{\bf{x}}} be an \eqn{m \times n} numeric matrix. The formula used to compute the norm is \eqn{\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}}}. } \value{ A numeric value. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. Golub, G. H. and C. F. Van Loan (1996). \emph{Matrix Computations}, Third Edition, The John Hopkins University Press. Horn, R. A. and C. R. Johnson (1985). \emph{Matrix Analysis}, Cambridge University Press. } \note{ 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. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{one.norm}}, \code{\link{inf.norm}} } \examples{ A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) print( entrywise.norm( A, 2 ) ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/fibonacci.matrix.Rd000077500000000000000000000022341274367517000213240ustar00rootroot00000000000000\name{fibonacci.matrix} \alias{fibonacci.matrix} \title{ Fibonacci Matrix } \description{ This function constructs the order n + 1 square Fibonacci matrix which is derived from a Fibonacci sequence. } \usage{ fibonacci.matrix(n) } \arguments{ \item{n}{ a positive integer value } } \details{ Let \eqn{\left\{ {{f_0},\;{f_1},\; \ldots ,\;{f_n}} \right\}} be the set of \eqn{ n + 1} Fibonacci numbers where \eqn{{f_0} = {f_1} = 1} and \eqn{{f_j} = {f_{j - 1}} + {f_{j - 2}},\quad 2 \le j \le n}. The order \eqn{n + 1} Fibonacci matrix \eqn{{\bf{F}}} has as typical element \eqn{{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.}. } \value{ An order \eqn{n + 1} matrix } \references{ Zhang, Z. and J. Wang (2006). Bernoulli matrix and its algebraic properties, \emph{Discrete Applied Nathematics}, 154, 1622-1632. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ If the argument n is not a positive integer, the function presents an error message and stops. } \examples{ F <- fibonacci.matrix( 10 ) print( F ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/frobenius.matrix.Rd000077500000000000000000000030071274367517000214020ustar00rootroot00000000000000\name{frobenius.matrix} \alias{frobenius.matrix} \title{ Frobenius Matrix } \description{ This function returns an order n Frobenius matrix that is useful in numerical mathematics. } \usage{ frobenius.matrix(n) } \arguments{ \item{n}{ a positive integer value greater than 1} } \details{ 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 \eqn{n} Frobenius matrix is \eqn{{\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]}. } \value{ An order \eqn{n} matrix } \references{ Aceto, L. and D. Trigiante (2001). Matrices of Pascal and Other Greats, \emph{American Mathematical Monthly}, March 2001, 108(3), 232-245. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ If the argument n is not a positive integer that is greater than 1, the function presents an error message and stops. } \examples{ F <- frobenius.matrix( 10 ) print( F ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/frobenius.norm.Rd000077500000000000000000000021051274367517000210470ustar00rootroot00000000000000\name{frobenius.norm} \alias{frobenius.norm} \title{ Compute the Frobenius norm of a matrix } \description{ This function returns the Frobenius norm of the matrix \eqn{{\mathbf{x}}}. } \usage{ frobenius.norm(x) } \arguments{ \item{x}{ a numeric vector or matrix } } \details{ The formula used to compute the norm is \eqn{\left\| {\bf{x}} \right\|_2}. Note that this is the entrywise norm with exponent 2. } \value{ A numeric value. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. Golub, G. H. and C. F. Van Loan (1996). \emph{Matrix Computations}, Third Edition, The John Hopkins University Press. Horn, R. A. and C. R. Johnson (1985). \emph{Matrix Analysis}, Cambridge University Press. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{entrywise.norm}} } \examples{ A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) print( frobenius.norm( A ) ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/frobenius.prod.Rd000077500000000000000000000027251274367517000210500ustar00rootroot00000000000000\name{frobenius.prod} \alias{frobenius.prod} \title{ Frobenius innter product of matrices } \description{ This function returns the Fronbenius inner product of two matrices, x and y, with the same row and column dimensions. } \usage{ frobenius.prod(x, y) } \arguments{ \item{x}{ a numeric matrix or vector object } \item{y}{ a numeric matrix or vector object } } \details{ The Frobenius inner product is the element-by-element sum of the Hadamard or Shur product of two numeric matrices. Let \eqn{{\bf{x}}} and \eqn{{\bf{y}}} be two \eqn{m \times n} matrices. Then Frobenious inner product is computed as \eqn{\sum\limits_{i = 1}^m {\sum\limits_{j = 1}^n {x_{i,j} \;y_{i,j} } } }. } \value{ A numeric value. } \references{ Styan, G. P. H. (1973). Hadamard Products and Multivariate Statistical Analysis, \emph{Linear Algebra and Its Applications}, Elsevier, 6, 217-240. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{hadamard.prod}} } \note{ 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. } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/hadamard.prod.Rd000077500000000000000000000034711274367517000206140ustar00rootroot00000000000000\name{hadamard.prod} \alias{hadamard.prod} \title{ Hadamard product of two matrices } \description{ This function returns the Hadamard or Shur product of two matrices, x and y, that have the same row and column dimensions. } \usage{ hadamard.prod(x, y) } \arguments{ \item{x}{ a numeric matrix or vector object } \item{y}{ a numeric matrix or vector object } } \details{ The Hadamard product is an element-by-element product of the two matrices. Let \eqn{{\bf{x}}} and \eqn{{\bf{x}}} be two \eqn{m \times n} numeric matrices. The Hadamard product is \eqn{{\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. } \value{ A matrix. } \references{ Hadamard, J (1983). Resolution d'une question relative aux determinants, \emph{Bulletin des Sciences Mathematiques}, 17, 240-246. Styan, G. P. H. (1973). Hadamard Products and Multivariate Statistical Analysis, \emph{Linear Algebra and Its Applications}, Elsevier, 6, 217-240. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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. } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/hankel.matrix.Rd000077500000000000000000000023151274367517000206510ustar00rootroot00000000000000\name{hankel.matrix} \alias{hankel.matrix} \title{ Hankel Matrix } \description{ 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. } \usage{ hankel.matrix(n, x) } \arguments{ \item{n}{ a positive integer value for order of matrix greater than 1 } \item{x}{ a vector of values used to construct the matrix } } \details{ 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. } \value{ An order \eqn{n} matrix. } \references{ Power, S. C. (1982). \emph{Hankel Operators on Hilbert Spaces}, Research notes in mathematics, Series 64, Pitman Publishing. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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. } \examples{ H <- hankel.matrix( 4, seq( 1, 7 ) ) print( H ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/hilbert.matrix.Rd000077500000000000000000000017661274367517000210510ustar00rootroot00000000000000\name{hilbert.matrix} \alias{hilbert.matrix} \title{ Hilbert matrices } \description{ This function returns an n by n Hilbert matrix. } \usage{ hilbert.matrix(n) } \arguments{ \item{n}{ Order of the Hilbert matrix } } \details{ A Hilbert matrix is an order \eqn{n} square matrix of unit fractions with elements defined as \eqn{H_{i,j} = {1 \mathord{\left/ {\vphantom {1 {\left( {i + j - 1} \right)}}} \right. \kern-\nulldelimiterspace} {\left( {i + j - 1} \right)}}}. } \value{ A matrix. } \references{ Hilbert, David (1894). Ein Beitrag zur Theorie des Legendre schen Polynoms, \emph{Acta Mathematica}, Springer, Netherlands, 18, 155-159. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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. } \examples{ H <- hilbert.matrix( 4 ) print( H ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/hilbert.schmidt.norm.Rd000077500000000000000000000021461274367517000221430ustar00rootroot00000000000000\name{hilbert.schmidt.norm} \alias{hilbert.schmidt.norm} \title{ Compute the Hilbert-Schmidt norm of a matrix } \description{ This function returns the Hilbert-Schmidt norm of the matrix \eqn{{\mathbf{x}}}. } \usage{ hilbert.schmidt.norm(x) } \arguments{ \item{x}{ a numeric vector or matrix } } \details{ The formula used to compute the norm is \eqn{\left\| {\bf{x}} \right\|_2}. This is merely the entrywise norm with exponent 2. } \value{ A numeric value. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. Golub, G. H. and C. F. Van Loan (1996). \emph{Matrix Computations}, Third Edition, The John Hopkins University Press. Horn, R. A. and C. R. Johnson (1985). \emph{Matrix Analysis}, Cambridge University Press. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{entrywise.norm}} } \examples{ A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) print( hilbert.schmidt.norm( A ) ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/inf.norm.Rd000077500000000000000000000024051274367517000176320ustar00rootroot00000000000000\name{inf.norm} \alias{inf.norm} \title{ Compute the infinitity norm of a matrix } \description{ This function returns the \eqn{\left\| {\mathbf{x}} \right\|_\infty } norm of the matrix \eqn{{\mathbf{x}}}. } \usage{ inf.norm(x) } \arguments{ \item{x}{ a numeric vector or matrix } } \details{ Let \eqn{{\bf{x}}} be an \eqn{m \times n} numeric matrix. The formula used to compute the norm is \eqn{\left\| {\bf{x}} \right\|_\infty = \mathop {\max }\limits_{1 \le i \le m} \sum\limits_{j = 1}^n {\left| {x_{i,j} } \right|} }. This is merely the maximum absolute row sum of the \eqn{m \times n} maxtris. } \value{ A numeric value. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. Golub, G. H. and C. F. Van Loan (1996). \emph{Matrix Computations}, Third Edition, The John Hopkins University Press. Horn, R. A. and C. R. Johnson (1985). \emph{Matrix Analysis}, Cambridge University Press. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{one.norm}} } \examples{ A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) print( inf.norm( A ) ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/is.diagonal.matrix.Rd000077500000000000000000000021431274367517000215760ustar00rootroot00000000000000\name{is.diagonal.matrix} \alias{is.diagonal.matrix} \title{ Test for diagonal square matrix } \description{ This function returns \code{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 \code{FALSE} value is returned. } \usage{ is.diagonal.matrix(x, tol = 1e-08) } \arguments{ \item{x}{ a numeric square matrix } \item{tol}{ a numeric tolerance level usually left out } } \value{ A TRUE or FALSE value. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. Horn, R. A. and C. R. Johnson (1990). \emph{Matrix Analysis}, Cambridge University Press. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/is.idempotent.matrix.Rd000077500000000000000000000055041274367517000221740ustar00rootroot00000000000000\name{is.idempotent.matrix} \alias{is.idempotent.matrix} \title{ Test for idempotent square matrix } \description{ This function returns a \code{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 \code{FALSE} value is returned. } \usage{ is.idempotent.matrix(x, tol = 1e-08) } \arguments{ \item{x}{ a numeric square matrix } \item{tol}{ a numeric tolerance level usually left out } } \details{ Idempotent matrices are used in econometric analysis. Consider the problem of estimating the regression parameters of a standard linear model \eqn{{\bf{y}} = {\bf{X}}\;{\bf{\beta }} + {\bf{e}}} using the method of least squares. \eqn{{\bf{y}}} is an order \eqn{m} random vector of dependent variables. \eqn{{\bf{X}}} is an \eqn{m \times n} matrix whose columns are columns of observations on one of the \eqn{ n - 1} independent variables. The first column contains \eqn{m} ones. \eqn{{\bf{e}}} is an order \eqn{m} random vector of zero mean residual values. \eqn{{\bf{\beta }}} is the order \eqn{n} vector of regression parameters. The objective function that is minimized in the method of least squares is \eqn{\left( {{\bf{y}} - {\bf{X}}\;{\bf{\beta }}} \right)^\prime \left( {{\bf{y}} - {\bf{X}}\;{\bf{\beta }}} \right)}. The solution to ths quadratic programming problem is \eqn{{\bf{\hat \beta }} = \left[ {\left( {{\bf{X'}}\;{\bf{X}}} \right)^{ - 1} \;{\bf{X'}}} \right]\;{\bf{y}}} The corresponding estimator for the residual vector is \eqn{{\bf{\hat e}} = {\bf{y}} - {\bf{X}}\;{\bf{\hat \beta }} = \left[ {{\bf{I}} - {\bf{X}}\;\left( {{\bf{X'}}\;{\bf{X}}} \right)^{ - 1} {\bf{X'}}} \right]{\bf{y}} = {\bf{M}}\;{\bf{y}}}. \eqn{{\bf{M}}} and \eqn{{{\bf{X}}\;\left( {{\bf{X'}}\;{\bf{X}}} \right)^{ - 1} {\bf{X'}}}} are idempotent. Idempotency of \eqn{{\bf{M}}} enters into the estimation of the variance of the estimator. } \value{ A TRUE or FALSE value. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. Chang, A. C., (1984). \emph{Fundamental Methods of Mathematical Economics}, Third edition, McGraw-Hill. Green, W. H. (2003). \emph{Econometric Analysis}, Fifth edition, Prentice-Hall. Horn, R. A. and C. R. Johnson (1990). \emph{Matrix Analysis}, Cambridge University Press. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/is.indefinite.Rd000077500000000000000000000043201274367517000206320ustar00rootroot00000000000000\name{is.indefinite} \alias{is.indefinite} \title{ Test matrix for positive indefiniteness } \description{ 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. } \usage{ is.indefinite(x, tol=1e-8) } \arguments{ \item{x}{ a matrix } \item{tol}{ a numeric tolerance level } } \details{ For an indefinite matrix, the matrix should positive and negative eigenvalues. The R function \code{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. } \value{ TRUE or FALSE. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{is.positive.definite}}, \code{\link{is.positive.semi.definite}}, \code{\link{is.negative.definite}}, \code{\link{is.negative.semi.definite}} } \examples{ ### ### 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/is.negative.definite.Rd000077500000000000000000000044041274367517000221070ustar00rootroot00000000000000\name{is.negative.definite} \alias{is.negative.definite} \title{ Test matrix for negative definiteness } \description{ This function returns TRUE if the argument, a square symmetric real matrix x, is negative definite. } \usage{ is.negative.definite(x, tol=1e-8) } \arguments{ \item{x}{ a matrix } \item{tol}{ a numeric tolerance level } } \details{ For a negative definite matrix, the eigenvalues should be negative. The R function \code{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. } \value{ TRUE or FALSE. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{is.positive.definite}}, \code{\link{is.positive.semi.definite}}, \code{\link{is.negative.semi.definite}}, \code{\link{is.indefinite}} } \examples{ ### ### 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/is.negative.semi.definite.Rd000077500000000000000000000045031274367517000230430ustar00rootroot00000000000000\name{is.negative.semi.definite} \alias{is.negative.semi.definite} \title{ Test matrix for negative semi definiteness } \description{ This function returns TRUE if the argument, a square symmetric real matrix x, is negative semi-negative. } \usage{ is.negative.semi.definite(x, tol=1e-8) } \arguments{ \item{x}{ a matrix } \item{tol}{ a numeric tolerance level } } \details{ For a negative semi-definite matrix, the eigenvalues should be non-positive. The R function \code{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. } \value{ TRUE or FALSE. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{is.positive.definite}}, \code{\link{is.positive.semi.definite}}, \code{\link{is.negative.definite}}, \code{\link{is.indefinite}} } \examples{ ### ### 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/is.non.singular.matrix.Rd000077500000000000000000000023121274367517000224330ustar00rootroot00000000000000\name{is.non.singular.matrix} \alias{is.non.singular.matrix} \title{ Test if matrix is non-singular } \description{ This function returns \code{TRUE} is the matrix argument is non-singular and \code{FALSE} otherwise. } \usage{ is.non.singular.matrix(x, tol = 1e-08) } \arguments{ \item{x}{ a numeric square matrix } \item{tol}{ a numeric tolerance level usually left out } } \details{ The determinant of the matrix \code{x} is first computed. If the absolute value of the determinant is greater than or equal to the given tolerance level, then a \code{TRUE} value is returned. Otherwise, a \code{FALSE} value is returned. } \value{ TRUE or FALSE value. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. Horn, R. A. and C. R. Johnson (1990). \emph{Matrix Analysis}, Cambridge University Press. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{is.singular.matrix}} } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/is.positive.definite.Rd000077500000000000000000000044001274367517000221430ustar00rootroot00000000000000\name{is.positive.definite} \alias{is.positive.definite} \title{ Test matrix for positive definiteness } \description{ This function returns TRUE if the argument, a square symmetric real matrix x, is positive definite. } \usage{ is.positive.definite(x, tol=1e-8) } \arguments{ \item{x}{ a matrix } \item{tol}{ a numeric tolerance level } } \details{ For a positive definite matrix, the eigenvalues should be positive. The R function \code{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. } \value{ TRUE or FALSE. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{is.positive.semi.definite}}, \code{\link{is.negative.definite}}, \code{\link{is.negative.semi.definite}}, \code{\link{is.indefinite}} } \examples{ ### ### 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/is.positive.semi.definite.Rd000077500000000000000000000043051274367517000231030ustar00rootroot00000000000000\name{is.positive.semi.definite} \alias{is.positive.semi.definite} \title{ Test matrix for positive semi-definiteness } \description{ This function returns TRUE if the argument, a square symmetric real matrix x, is positive semi-definite. } \usage{ is.positive.semi.definite(x, tol=1e-8) } \arguments{ \item{x}{ a matrix } \item{tol}{ a numeric tolerance level } } \details{ For a positive semi-definite matrix, the eigenvalues should be non-negative. The R function \code{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. } \value{ TRUE or FALSE. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{is.positive.definite}}, \code{\link{is.negative.definite}}, \code{\link{is.negative.semi.definite}}, \code{\link{is.indefinite}} } \examples{ ### ### 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/is.singular.matrix.Rd000077500000000000000000000022531274367517000216460ustar00rootroot00000000000000\name{is.singular.matrix} \alias{is.singular.matrix} \title{ Test for singular square matrix } \description{ This function returns \code{TRUE} is the matrix argument is singular and \code{FALSE} otherwise. } \usage{ is.singular.matrix(x, tol = 1e-08) } \arguments{ \item{x}{ a numeric square matrix } \item{tol}{ a numeric tolerance level usually left out } } \details{ The determinant of the matrix \code{x} is first computed. If the absolute value of the determinant is less than the given tolerance level, then a \code{TRUE} value is returned. Otherwise, a \code{FALSE} value is returned. } \value{ A TRUE or FALSE value. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. Horn, R. A. and C. R. Johnson (1990). \emph{Matrix Analysis}, Cambridge University Press. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{is.non.singular.matrix}} } \examples{ A <- diag( 1, 3 ) is.singular.matrix( A ) B <- matrix( c( 0, 0, 3, 4 ), nrow=2, byrow=TRUE ) is.singular.matrix( B ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/is.skew.symmetric.matrix.Rd000077500000000000000000000025431274367517000230100ustar00rootroot00000000000000\name{is.skew.symmetric.matrix} \alias{is.skew.symmetric.matrix} \title{ Test for a skew-symmetric matrix } \description{ This function returns \code{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, \code{FALSE} is returned. } \usage{ is.skew.symmetric.matrix(x, tol = 1e-08) } \arguments{ \item{x}{ a numeric square matrix } \item{tol}{ a numeric tolerance level usually left out } } \details{ Let \eqn{{\bf{x}}} be an order \eqn{n} matrix. If every element of the matrix \eqn{{\bf{x}} + {\bf{x'}}} in absolute value is less than the given tolerance, then the matrix argument is declared to be skew symmetric. } \value{ A TRUE or FALSE value. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. Horn, R. A. and C. R. Johnson (1990). \emph{Matrix Analysis}, Cambridge University Press. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/is.square.matrix.Rd000077500000000000000000000012701274367517000213200ustar00rootroot00000000000000\name{is.square.matrix} \alias{is.square.matrix} \title{ Test for square matrix } \description{ The function returns TRUE if the argument is a square matrix and FALSE otherwise. } \usage{ is.square.matrix(x) } \arguments{ \item{x}{ a matrix } } \value{ TRUE or FALSE } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/is.symmetric.matrix.Rd000077500000000000000000000017401274367517000220360ustar00rootroot00000000000000\name{is.symmetric.matrix} \alias{is.symmetric.matrix} \title{ Test for symmetric numeric matrix } \description{ This function returns TRUE if the argument is a numeric symmetric square matrix and FALSE otherwise. } \usage{ is.symmetric.matrix(x) } \arguments{ \item{x}{ an R object } } \value{ TRUE or FALSE. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. } \note{ 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. } \seealso{ \code{\link{is.square.matrix}} } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/lower.triangle.Rd000077500000000000000000000012311274367517000210340ustar00rootroot00000000000000\name{lower.triangle} \alias{lower.triangle} \title{ Lower triangle portion of a matrix } \description{ Returns the lower triangle including the diagonal of a square numeric matrix. } \usage{ lower.triangle(x) } \arguments{ \item{x}{ a matrix } } \value{ A matrix. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. } \seealso{ \code{\link{is.square.matrix}} } \examples{ B <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) lower.triangle( B ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/lu.decomposition.Rd000077500000000000000000000030521274367517000213760ustar00rootroot00000000000000\name{lu.decomposition} \alias{lu.decomposition} \title{ LU Decomposition of Square Matrix } \description{ 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 } \usage{ lu.decomposition(x) } \arguments{ \item{x}{ a numeric square matrix } } \details{ The Doolittle decomposition without row exchanges is performed generating the lower and upper triangular matrices separately rather than in one matrix. } \value{ A list with two named components. \item{L }{The numeric lower triangular matrix} \item{U }{The number upper triangular matrix} } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. Golub, G. H. and C. F. Van Loan (1996). \emph{Matrix Computations}, Third Edition, John Hopkins University Press Horn, R. A. and C. R. Johnson (1985). \emph{Matrix Analysis}, Cambridge University Press. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/matrix.inverse.Rd000077500000000000000000000013151274367517000210610ustar00rootroot00000000000000\name{matrix.inverse} \alias{matrix.inverse} \title{ Inverse of a square matrix } \description{ This function returns the inverse of a square matrix computed using the R function solve. } \usage{ matrix.inverse(x) } \arguments{ \item{x}{ a square numeric matrix } } \value{ A matrix. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/matrix.power.Rd000077500000000000000000000020721274367517000205430ustar00rootroot00000000000000\name{matrix.power} \alias{matrix.power} \title{ Matrix Raised to a Power } \description{ 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. } \usage{ matrix.power(x, k) } \arguments{ \item{x}{ a numeric square matrix } \item{k}{ a numeric exponent } } \details{ 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. } \value{ An order \eqn{n} matrix. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/matrix.rank.Rd000077500000000000000000000022031274367517000203360ustar00rootroot00000000000000\name{matrix.rank} \alias{matrix.rank} \title{ Rank of a square matrix } \description{ This function returns the rank of a square numeric matrix based on the selected method. } \usage{ matrix.rank(x, method = c("qr", "chol")) } \arguments{ \item{x}{ a matrix } \item{method}{ a character string that specifies the method to be used } } \details{ 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. } \value{ An integer. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ If the argument is not a square numeric matrix, then the function presents an error message and stops. } \seealso{ \code{\link{is.square.matrix}} } \examples{ A <- diag( seq( 1, 4, 1 ) ) matrix.rank( A ) B <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) matrix.rank( B ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/matrix.trace.Rd000077500000000000000000000015121274367517000205030ustar00rootroot00000000000000\name{matrix.trace} \alias{matrix.trace} \title{ The trace of a matrix } \description{ This function returns the trace of a given square numeric matrix. } \usage{ matrix.trace(x) } \arguments{ \item{x}{ a matrix } } \value{ A numeric value which is the sum of the values on the diagonal. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. } \note{ 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. } \examples{ A <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) matrix.trace( A ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/maximum.norm.Rd000077500000000000000000000021261274367517000205330ustar00rootroot00000000000000\name{maximum.norm} \alias{maximum.norm} \title{ Maximum norm of matrix } \description{ This function returns the max norm of a real matrix. } \usage{ maximum.norm(x) } \arguments{ \item{x}{ a numeric matrix or vector } } \details{ Let \eqn{{\bf{x}}} be an \eqn{m \times n} real matrix. The max norm returned is \eqn{\left\| {\bf{x}} \right\|_{\max } = \mathop {\max }\limits_{i,j} \left| {x_{i,j} } \right|}. } \value{ A numeric value. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. Golub, G. H. and C. F. Van Loan (1996). \emph{Matrix Computations}, Third Edition, The John Hopkins University Press. Horn, R. A. and C. R. Johnson (1985). \emph{Matrix Analysis}, Cambridge University Press. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{inf.norm}}, \code{\link{one.norm}} } \examples{ A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) maximum.norm( A ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/one.norm.Rd000077500000000000000000000023361274367517000176420ustar00rootroot00000000000000\name{one.norm} \alias{one.norm} \title{ Compute the one norm of a matrix } \description{ This function returns the \eqn{\left\| {\bf{x}} \right\|_1 } norm of the matrix \eqn{{\mathbf{x}}}. } \usage{ one.norm(x) } \arguments{ \item{x}{ a numeric vector or matrix } } \details{ Let \eqn{{\bf{x}}} be an \eqn{m \times n} matrix. The formula used to compute the norm is \eqn{\left\| {\bf{x}} \right\|_1 = \mathop {\max }\limits_{1 \le j \le n} \sum\limits_{i = 1}^m {\left| {x_{i,j} } \right|} }. This is merely the maximum absolute column sum of the \eqn{m \times n} maxtris. } \value{ A numeric value. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. Golub, G. H. and C. F. Van Loan (1996). \emph{Matrix Computations}, Third Edition, The John Hopkins University Press. Horn, R. A. and C. R. Johnson (1985). \emph{Matrix Analysis}, Cambridge University Press. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{inf.norm}} } \examples{ A <- matrix( c( 3, 5, 7, 2, 6, 4, 0, 2, 8 ), nrow=3, ncol=3, byrow=TRUE ) one.norm( A ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/pascal.matrix.Rd000077500000000000000000000024421274367517000206530ustar00rootroot00000000000000\name{pascal.matrix} \alias{pascal.matrix} \title{ Pascal matrix } \description{ This function returns an n by n Pascal matrix. } \usage{ pascal.matrix(n) } \arguments{ \item{n}{ Order of the matrix } } \details{ 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. } \value{ An order \eqn{n} matrix. } \references{ Aceto, L. and D. Trigiante, (2001). Matrices of Pascal and Other Greats, \emph{American Mathematical Monthly}, March 2001, 232-245. Call, G. S. and D. J. Velleman, (1993). Pascal's matrices, \emph{American Mathematical Monthly}, April 1993, 100, 372-376. Edelman, A. and G. Strang, (2004). Pascal Matrices, \emph{American Mathematical Monthly}, 111(3), 361-385. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ If the argument n is not a positive integer, the function presents an error message and stops. } \seealso{ \code{\link{lu.decomposition}}, \code{\link{symmetric.pascal.matrix}} } \examples{ P <- pascal.matrix( 4 ) print( P ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/s.Rd000077500000000000000000000020001274367517000163350ustar00rootroot00000000000000\name{\%s\%} \alias{\%s\%} \title{ Direct sum of two arrays } \description{ This function computes the direct sum of two arrays. The arrays can be numerical vectors or matrices. The result ia the block diagonal matrix. } \usage{ x\%s\%y } \arguments{ \item{x}{ a numeric matrix or vector } \item{y}{ a numeric matrix or vector } } \value{ A numeric matrix. } \details{ If either \eqn{\bf{x}} or y is a vector, it is converted to a matrix. The result is a block diagonal matrix \eqn{\left[ {\begin{array}{*{20}c} {\bf{x}} & {\bf{0}} \\ {\bf{0}} & {\bf{y}} \\ \end{array}} \right]}. } \references{ Magnus, J. R. and H. Neudecker (1999) \emph{Matrix Differential Calculus with Applications in Statistics and Econometrics}, Second Edition, John Wiley. } \author{ Frederick Novomestky \email{fnovomes@poly.edu}, Kurt Hornik \email{Kurt.Hornik@wu-wien.ac.at} } \examples{ x <- matrix( seq( 1, 4 ) ) y <- matrix( seq( 5, 8 ) ) print( x \%s\% y ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/set.submatrix.Rd000077500000000000000000000025551274367517000207220ustar00rootroot00000000000000\name{set.submatrix} \alias{set.submatrix} \title{ Store matrix inside another matrix } \description{ 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. } \usage{ set.submatrix(x, y, row, col) } \arguments{ \item{x}{ a matrix } \item{y}{ a matrix } \item{row}{ an integer row number } \item{col}{ an integer column number } } \value{ A matrix. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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. } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/shift.down.Rd000077500000000000000000000015151274367517000201700ustar00rootroot00000000000000\name{shift.down} \alias{shift.down} \title{ Shift matrix m rows down } \description{ This function returns a matrix that has had its rows shifted downwards filling the above rows with the given fill value. } \usage{ shift.down(A, rows = 1, fill = 0) } \arguments{ \item{A}{ a matrix } \item{rows}{ the number of rows to be shifted } \item{fill}{ the fill value which as a default is zero } } \value{ A matrix. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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. } \examples{ A <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) shift.down( A, 1 ) shift.down( A, 3 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/shift.left.Rd000077500000000000000000000015671274367517000201620ustar00rootroot00000000000000\name{shift.left} \alias{shift.left} \title{ Shift a matrix n columns to the left } \description{ This function returns a matrix that has been shifted n columns to the left filling the subsqeuent columns with the given fill value } \usage{ shift.left(A, cols = 1, fill = 0) } \arguments{ \item{A}{ a matrix } \item{cols}{ integer number of columns to be shifted to the left } \item{fill}{ the fill value which as as a default zero } } \value{ A matrix. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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. } \examples{ A <- matrix( seq( 1, 12, 1 ), nrow=3, byrow=TRUE ) shift.left( A, 1 ) shift.left( A, 2 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/shift.right.Rd000077500000000000000000000015661274367517000203440ustar00rootroot00000000000000\name{shift.right} \alias{shift.right} \title{Shift matrix n columns to the right } \description{ This function returns a matrix that has been shifted to the right n columns filling the previous columns with the given fill value. } \usage{ shift.right(A, cols = 1, fill = 0) } \arguments{ \item{A}{ a matrix } \item{cols}{ integer number of columns to be shifted to the right } \item{fill}{ the fill which as default value zero } } \value{ A matrix. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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. } \examples{ A <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) shift.right( A, 1 ) shift.right( A, 2 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/shift.up.Rd000077500000000000000000000015221274367517000176430ustar00rootroot00000000000000\name{shift.up} \alias{shift.up} \title{ Shift matrix m rows up } \description{ 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. } \usage{ shift.up(A, rows = 1, fill = 0) } \arguments{ \item{A}{ a matrix } \item{rows}{ integer number of rows} \item{fill}{ fill value which as the default value of zero } } \value{ A matrix. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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. } \examples{ A <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) shift.up( A, 1 ) shift.up( A, 3 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/spectral.norm.Rd000077500000000000000000000036061274367517000206770ustar00rootroot00000000000000\name{spectral.norm} \alias{spectral.norm} \title{ Spectral norm of matrix } \description{ This function returns the spectral norm of a real matrix. } \usage{ spectral.norm(x) } \arguments{ \item{x}{ a numeric matrix or vector } } \details{ Let \eqn{{\bf{x}}} be an \eqn{m \times n} real matrix. The function computes the order \eqn{n} square matrixmatrix \eqn{{\bf{A}} = {\bf{x'}}\;{\bf{x}}}. The R function \code{eigen} is applied to this matrix to obtain the vector of eigenvalues \eqn{{\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 \eqn{\lambda _1}. Then the spectral norm is \eqn{\left\| {\bf{x}} \right\|_2 = \sqrt {\lambda _1 }}. If \eqn{{\bf{x}}} is a vector, then \eqn{{\bf{L}}_2 = \sqrt {\bf{A}}} is returned. } \value{ A numeric value. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. Golub, G. H. and C. F. Van Loan (1996). \emph{Matrix Computations}, Third Edition, The John Hopkins University Press. Horn, R. A. and C. R. Johnson (1985). \emph{Matrix Analysis}, Cambridge University Press. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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 \eqn{{\bf{x'}}\;{\bf{x}}} is negative definite, an error message displayed and the function terminates. } \examples{ x <- matrix( c( 2, 4, 2, 1, 3, 1, 5, 2, 1, 2, 3, 3 ), nrow=4, ncol=4, byrow=TRUE ) spectral.norm( x ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/stirling.matrix.Rd000077500000000000000000000033151274367517000212430ustar00rootroot00000000000000\name{stirling.matrix} \alias{stirling.matrix} \title{ Stirling Matrix } \description{ This function constructs and returns a Stirling matrix which is a lower triangular matrix containing the Stirling numbers of the second kind. } \usage{ stirling.matrix(n) } \arguments{ \item{n}{ A positive integer value } } \details{ The Stirling numbers of the second kind, \eqn{S_i^j}, are used in combinatorics to compute the number of ways a set of \eqn{i} objects can be partitioned into \eqn{j} non-empty subsets \eqn{j \le i}. The numbers are also denoted by \eqn{\left\{ {\begin{array}{*{20}{c}}i\\j\end{array}} \right\}}. Stirling numbers of the second kind can be computed recursively with the equation \eqn{S_j^{i + 1} = S_{j - 1}^i + j\;S_j^i,\quad 1 \le i \le n - 1,\;1 \le j \le i}. The initial conditions for the recursion are \eqn{S_i^i = 1,\quad 0 \le i \le n} and \eqn{S_j^0 = S_0^j = 0,\quad 0 \le j \le n}. The resultant numbers are organized in an order \eqn{n + 1} matrix \eqn{\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]}. } \value{ An order \eqn{n + 1} lower triangular matrix. } \references{ Aceto, L. and D. Trigiante (2001). Matrices of Pascal and Other Greats, \emph{American Mathematical Monthly}, March 2001, 108(3), 232-245. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ If the argument n is not a positive integer, the function presents an error message and stops. } \examples{ S <- stirling.matrix( 10 ) print( S ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/svd.inverse.Rd000077500000000000000000000017431274367517000203560ustar00rootroot00000000000000\name{svd.inverse} \alias{svd.inverse} \title{ SVD Inverse of a square matrix } \description{ 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 \code{solve} function. If the matrix is not a square matrix, then the result is the Moore-Penrose pseudo inverse. } \usage{ svd.inverse(x) } \arguments{ \item{x}{ a numeric matrix } } \value{ A matrix. } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \examples{ 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 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/symmetric.pascal.matrix.Rd000077500000000000000000000027241274367517000226710ustar00rootroot00000000000000\name{symmetric.pascal.matrix} \alias{symmetric.pascal.matrix} \title{ Symmetric Pascal matrix } \description{ This function returns an n by n symmetric Pascal matrix. } \usage{ symmetric.pascal.matrix(n) } \arguments{ \item{n}{ Order of the matrix } } \details{ 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 \eqn{n} symmetric matrix with typical element given by \eqn{{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 \eqn{n = i + j - 2} and \eqn{r = i - 1}. The binomial coefficients are elegantly recovered from the symmetric Pascal matrix by performing an \eqn{LU} decomposition as \eqn{{\bf{S}} = {\bf{L}}\;{\bf{U}}}. } \value{ An order \eqn{n} matrix. } \references{ Call, G. S. and D. J. Velleman, (1993). Pascal's matrices, \emph{American Mathematical Monthly}, April 1993, 100, 372-376. Edelman, A. and G. Strang, (2004). Pascal Matrices, \emph{American Mathematical Monthly}, 111(3), 361-385. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ If the argument n is not a positive integer, the function presents an error message and stops. } \examples{ S <- symmetric.pascal.matrix( 4 ) print( S ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/toeplitz.matrix.Rd000077500000000000000000000017201274367517000212600ustar00rootroot00000000000000\name{toeplitz.matrix} \alias{toeplitz.matrix} \title{ Toeplitz Matrix } \description{ This function constructs an order n Toeplitz matrix from the values in the order 2 * n - 1 vector x. } \usage{ toeplitz.matrix(n, x) } \arguments{ \item{n}{ a positive integer value for order of matrix greater than 1 } \item{x}{ a vector of values used to construct the matrix } } \details{ The element \code{T[i,j]} in the Toeplitz matrix is \code{x[i-j+n]}. } \value{ An order n matrix. } \references{ Monahan, J. F. (2011). \emph{Numerical Methods of Statistics}, Cambridge University Press. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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. } \examples{ T <- toeplitz.matrix( 4, seq( 1, 7 ) ) print( T ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/u.vectors.Rd000077500000000000000000000031601274367517000200330ustar00rootroot00000000000000\name{u.vectors} \alias{u.vectors} \title{ u vectors of an identity matrix } \description{ 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. } \usage{ u.vectors(n) } \arguments{ \item{n}{ a positive integer value for the order of underlying matrices } } \details{ The function firsts constructs an identity matrix of order \eqn{\frac{1}{2}n\left( {n + 1} \right)}. \eqn{{{{\bf{u}}_{i,j}}}} is the column vector in the order \eqn{\frac{1}{2}n\left( {n + 1} \right)} identity matrix for column \eqn{k = \left( {j - 1} \right)n + i - \frac{1}{2}j\left( {j - 1} \right)}. } \value{ A list with two named components \item{k }{order \eqn{n} square matrix that maps each ordered pair (i,j) to a column in the identity matrix} \item{I }{order \eqn{\frac{1}{2}n\left( {n + 1} \right)} identity matrix} } \references{ Magnus, J. R. and H. Neudecker (1980). The elimination matrix, some lemmas and applications, \emph{SIAM Journal on Algebraic Discrete Methods}, 1(4), December 1980, 422-449. Magnus, J. R. and H. Neudecker (1999) \emph{Matrix Differential Calculus with Applications in Statistics and Econometrics}, Second Edition, John Wiley. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \note{ 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. } \examples{ u <- u.vectors( 3 ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/upper.triangle.Rd000077500000000000000000000012301274367517000210360ustar00rootroot00000000000000\name{upper.triangle} \alias{upper.triangle} \title{ Upper triangle portion of a matrix } \description{ Returns the lower triangle including the diagonal of a square numeric matrix. } \usage{ upper.triangle(x) } \arguments{ \item{x}{ a matrix } } \value{ A matrix. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \references{ Bellman, R. (1987). \emph{Matrix Analysis}, Second edition, Classics in Applied Mathematics, Society for Industrial and Applied Mathematics. } \seealso{ \code{\link{is.square.matrix}} } \examples{ A <- matrix( seq( 1, 9, 1 ), nrow=3, byrow=TRUE ) upper.triangle( A ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/vandermonde.matrix.Rd000077500000000000000000000025371274367517000217170ustar00rootroot00000000000000\name{vandermonde.matrix} \alias{vandermonde.matrix} \title{ Vandermonde matrix } \description{ This function returns an m by n matrix of the powers of the alpha vector } \usage{ vandermonde.matrix(alpha, n) } \arguments{ \item{alpha}{ A numerical vector of values } \item{n}{ The column dimension of the Vandermonde matrix } } \details{ In linear algebra, a Vandermonde matrix is an \eqn{m \times n} matrix with terms of a geometric progression of an \eqn{m \times 1} parameter vector \eqn{{\bf{\alpha }} = {\left[ {\begin{array}{*{20}{c}} {{\alpha _1}}&{{\alpha _2}}& \cdots &{{\alpha _m}} \end{array}} \right]^\prime }} such that \eqn{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]}. } \value{ A matrix. } \references{ Horn, R. A. and C. R. Johnson (1991). \emph{Topics in matrix analysis}, Cambridge University Press. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \examples{ alpha <- c( .1, .2, .3, .4 ) V <- vandermonde.matrix( alpha, 4 ) print( V ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/vec.Rd000077500000000000000000000012161274367517000166600ustar00rootroot00000000000000\name{vec} \alias{vec} \title{ Vectorize a matrix } \description{ This function returns a column vector that is a stack of the columns of x, an m by n matrix. } \usage{ vec(x) } \arguments{ \item{x}{ a matrix } } \value{ A matrix with \eqn{m\;n} rows and one column. } \references{ Magnus, J. R. and H. Neudecker (1999) \emph{Matrix Differential Calculus with Applications in Statistics and Econometrics}, Second Edition, John Wiley. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \examples{ x <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) print( x ) vecx <- vec( x ) print( vecx ) } \keyword{ math } r-cran-matrixcalc-1.0.3/man/vech.Rd000077500000000000000000000014051274367517000170300ustar00rootroot00000000000000\name{vech} \alias{vech} \title{ Vectorize a matrix } \description{ 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 } \usage{ vech(x) } \arguments{ \item{x}{ a matrix } } \value{ A matrix with \eqn{\frac{1}{2}n\left( {n + 1} \right)} rows and one column. } \references{ Magnus, J. R. and H. Neudecker (1999) \emph{Matrix Differential Calculus with Applications in Statistics and Econometrics}, Second Edition, John Wiley. } \author{ Frederick Novomestky \email{fnovomes@poly.edu} } \seealso{ \code{\link{is.square.matrix}} } \examples{ x <- matrix( seq( 1, 16, 1 ), nrow=4, byrow=TRUE ) print( x ) y <- vech( x ) print( y ) } \keyword{ math }