
R Under development (unstable) (2014-08-14 r66373) -- "Unsuffered Consequences"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: i686-pc-linux-gnu (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(bdsmatrix)

Attaching package: 'bdsmatrix'

The following object is masked from 'package:base':

    backsolve

> aeq <- function(x,y) all.equal(as.vector(x), as.vector(y))
> 
> tmat <- bdsmatrix(c(3,2,2,4), 
+ 	      c(22,1,2,21,3,20,19,4,18,17,5,16,15,6,7, 8,14,9,10,13,11,12),
+ 	      matrix(c(1,0,1,1,0,0,1,1,0,1,0,10,0,
+                        0,1,1,0,1,1,0,1,1,0,1,0,10), ncol=2))
> dimnames(tmat) <- list(NULL, letters[1:13])
> 
> smat <- as.matrix(tmat)
> 
> # Create a matrix that is symmetric, but not positive definite
> #   The first one, temp, has column 6 redundant with cols 1-5
> temp <- smat[c(1:5, 5:10), c(1:5, 5:10)]
> ch1  <- gchol(temp)
> aeq(diag(ch1)[6], 0)  # Check that it has a zero in the proper place
[1] TRUE
> ginv <- solve(ch1)    # see if I get a generalized inverse
> aeq(temp %*% ginv %*% temp, temp)
[1] TRUE
> aeq(ginv %*% temp %*% ginv, ginv)
[1] TRUE
> 
> # Now create one that is negative definite 
> ch2 <- gchol(smat)
> temp2 <- as.matrix(ch2)
> temp3 <- diag(ch2) * rep(c(1, -1), length=nrow(smat))
> xmat  <- temp2 %*% diag(temp3) %*% t(temp2)
> xmat  <- (xmat + t(xmat))/2  #work out round-off errors
> ch3 <- gchol(xmat)
> 
> aeq(diag(ch3), temp3)
[1] TRUE
> aeq(as.matrix(ch3), temp2)
[1] TRUE
> 
> proc.time()
   user  system elapsed 
  0.600   0.008   0.675 
