# NOT RUN {
# ---
# case of real matrices
m<-matrix(1:12,3,4)
m
diag(m) # first type usage
v<-c(1,5,9) # second type usage
diag(v)
diag(v,4)
diag(v,4,2)
diag(v,ncol=4)
# ---
# case of polynomial matrices
# first kind usage: catch the diagonal elements
px<-polyMgen.d(3,3,rawData=ch2pn(
c("-3 + z^2","2 + 4*z","-z^2",
"1","2","3 + z",
"2*z","0","2 - 3*z"),"z"),byrow=TRUE)
class(px) # "polyMdlist" "polyMatrix"
px
w<-diag(px) # the default: type="list"
class(w) # "list"
# List of 3
# $ :Class 'polynomial' num [1:3] -3 0 1
# $ :Class 'polynomial' num 2
# $ :Class 'polynomial' num [1:2] 2 -3
w
w<-diag(px,type="polyMatrix")
class(w) # "polyMdlist" "polyMatrix"
w
# second kind usage: compose a diagonal polyMatrix
ci<-c(4,1,3,2)
v<-vector("list",length(ci))
for(i in 1:length(ci))
v[[i]]<-polynom::polynomial(c(rep(0,ci[i]),1))
class(v) # "list"
v
diag(v)
diag(v,4)
diag(v,3)
diag(v,5)
diag(v,3,5)
pd<-diag(v,4,5)
class(pd) # "polyMdlist" "polyMatrix"
pd
# clean up
# rm(ci, i, m, pd, px, v, w)
# }
Run the code above in your browser using DataLab