R Under development (unstable) (2024-03-01 r86033 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 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) > yy <- c(30,35,42,56,34,45,32,37,78,56,40,52,39) > > # matrix multiplication > zz <- runif(13) > aeq(zz%*% smat, zz%*% tmat) [1] TRUE > aeq(smat%*%zz, tmat%*% zz) [1] TRUE > > xx <- matrix(1:39, ncol=3) > aeq(smat %*% zz, tmat %*% zz) [1] TRUE > aeq(t(xx) %*% smat, t(xx) %*% tmat) [1] TRUE > > > amat <- tmat > amat@offdiag <- pi > bmat <- as.matrix(amat) > > aeq(zz%*% amat, zz%*% bmat) [1] TRUE > aeq(amat%*%zz, bmat%*% zz) [1] TRUE > > > # Solve the right-hand side wrt a matrix > yy2 <- cbind(yy, -yy, yy+3) > zz1 <- solve(smat, yy2) > zz2 <- solve(tmat, yy2) > aeq(zz1, zz2) [1] TRUE > aeq(zz2[,1], solve(tmat, yy)) [1] TRUE > > proc.time() user system elapsed 0.26 0.07 0.34