diff options
Diffstat (limited to 'R/poly.R')
-rw-r--r-- | R/poly.R | 173 |
1 files changed, 73 insertions, 100 deletions
@@ -24,127 +24,100 @@ checkUnity <- function(x){ } #' @export -print.idpoly <- function(x){ - if(x$type=="arx"){ - print_arx(x) - } else if(x$type=="armax"){ - print_armax(x) - } else if(x$type=="oe"){ - print_oe(x) - } -} - -print_arx <- function(obj){ - cat("Discrete-time ARX model: A(q^{-1})y[k] = B(q^{-1})u[k] + e[k] \n\n") - cat("A(q^{-1}) = ") - for(i in seq_along(obj$A)){ - if(i-1==0){ - cat(obj$A[i]) - } else{ - if(obj$A[i]>0) cat(" + ") else cat("- ") - - if(!(abs(obj$A[i])==1)) cat(abs(obj$A[i])) - cat("q^{-",i-1,"}",sep="") - } - cat("\t") +print.idpoly <- function(mod){ + + if(mod$type=="arx"){ + cat("Discrete-time ARX mod: A(q^{-1})y[k] = B(q^{-1})u[k] + e[k] \n\n") + } else if(mod$type=="armax"){ + cat("Discrete-time ARMAX mod: A(q^{-1})y[k] = B(q^{-1})u[k] + C(q^{-1})e[k] \n\n") + } else if(mod$type=="oe"){ + cat("Discrete-time OE mod: y[k] = B(q^{-1})/F(q^{-1}) u[k] + e[k] \n\n") + } else if(mod$type=="bj"){ + cat("Discrete-time BJ mod: y[k] = B(q^{-1})/F(q^{-1}) u[k] + C(q^{-1})/D(q^{-1}) e[k] \n\n") + } else{ + cat("Discrete-time Polynomial mod: A(q^{-1}) y[k] = B(q^{-1})/F(q^{-1}) u[k] + C(q^{-1})/D(q^{-1}) e[k] \n\n") } - cat("\n") - cat("B(q^{-1}) = ") - for(i in seq_along(obj$B)){ - if(i+obj$ioDelay-1==0){ - cat(obj$B[i]) - } else{ - - if(!((obj$ioDelay!=0) && (i==1))){ - if(obj$B[i]>0) cat(" + ") else cat("- ") + + + if(length(mod$A)>1){ + cat("A(q^{-1}) = ") + for(i in seq_along(mod$A)){ + if(i-1==0){ + cat(mod$A[i]) } else{ - if(obj$B[i]<0) cat("-") + if(mod$A[i]>0) cat(" + ") else cat("- ") + + if(!(abs(mod$A[i])==1)) cat(abs(mod$A[i])) + cat("q^{-",i-1,"}",sep="") } - - if(!(abs(obj$B[i])==1)) cat(abs(obj$B[i])) - cat("q^{-",i+obj$ioDelay-1,"}",sep="") - } - cat("\t") - } -} - -print_armax <- function(obj){ - cat("Discrete-time ARMAX model: A(q^{-1})y[k] = B(q^{-1})u[k] + C(q^{-1})e[k] \n\n") - cat("A(q^{-1}) = ") - for(i in seq_along(obj$A)){ - if(i-1==0){ - cat(obj$A[i]) - } else{ - if(obj$A[i]>0) cat(" + ") else cat("- ") - - if(!(abs(obj$A[i])==1)) cat(abs(obj$A[i])) - cat("q^{-",i-1,"}",sep="") + cat("\t") } - cat("\t") + cat("\n") } - cat("\n") + cat("B(q^{-1}) = ") - for(i in seq_along(obj$B)){ - if(i+obj$ioDelay-1==0){ - cat(obj$B[i]) + for(i in seq_along(mod$B)){ + if(i+mod$ioDelay-1==0){ + cat(mod$B[i]) } else{ - if(!((obj$ioDelay!=0) && (i==1))){ - if(obj$B[i]>0) cat(" + ") else cat("- ") + if(!((mod$ioDelay!=0) && (i==1))){ + if(mod$B[i]>0) cat(" + ") else cat("- ") } else{ - if(obj$B[i]<0) cat("-") + if(mod$B[i]<0) cat("-") } - if(!(abs(obj$B[i])==1)) cat(abs(obj$B[i])) - cat("q^{-",i+obj$ioDelay-1,"}",sep="") + if(!(abs(mod$B[i])==1)) cat(abs(mod$B[i])) + cat("q^{-",i+mod$ioDelay-1,"}",sep="") } cat("\t") } cat("\n") - cat("C(q^{-1}) = ") - for(i in seq_along(obj$C)){ - if(i-1==0){ - cat(obj$C[i]) - } else{ - if(obj$C[i]>0) cat(" + ") else cat("- ") - - if(!(abs(obj$C[i])==1)) cat(abs(obj$C[i])) - cat("q^{-",i-1,"}",sep="") + + if(length(mod$C)>1){ + cat("C(q^{-1}) = ") + for(i in seq_along(mod$C)){ + if(i-1==0){ + cat(mod$C[i]) + } else{ + if(mod$C[i]>0) cat(" + ") else cat("- ") + + if(!(abs(mod$C[i])==1)) cat(abs(mod$C[i])) + cat("q^{-",i-1,"}",sep="") + } + cat("\t") } - cat("\t") + cat("\n") } -} - -print_oe <- function(obj){ - cat("Discrete-time OE model: y[k] = B(q^{-1})/F(q^{-1}) u[k] + e[k] \n\n") - cat("B(q^{-1}) = ") - for(i in seq_along(obj$B)){ - if(i+obj$ioDelay-1==0){ - cat(obj$B[i]) - } else{ - - if(!((obj$ioDelay!=0) && (i==1))){ - if(obj$B[i]>0) cat(" + ") else cat("- ") + + if(length(mod$D)>1){ + cat("D(q^{-1}) = ") + for(i in seq_along(mod$D)){ + if(i-1==0){ + cat(mod$D[i]) } else{ - if(obj$B[i]<0) cat("-") + if(mod$D[i]>0) cat(" + ") else cat("- ") + + if(!(abs(mod$D[i])==1)) cat(abs(mod$D[i])) + cat("q^{-",i-1,"}",sep="") } - - if(!(abs(obj$B[i])==1)) cat(abs(obj$B[i])) - cat("q^{-",i+obj$ioDelay-1,"}",sep="") + cat("\t") } - cat("\t") + cat("\n") } - cat("\n") - cat("F(q^{-1}) = ") - for(i in seq_along(obj$F1)){ - if(i-1==0){ - cat(obj$F1[i]) - } else{ - if(obj$F1[i]>0) cat(" + ") else cat("- ") - - if(!(abs(obj$F1[i])==1)) cat(abs(obj$F1[i])) - cat("q^{-",i-1,"}",sep="") + + if(length(mod$F1)>1){ + cat("F(q^{-1}) = ") + for(i in seq_along(mod$F1)){ + if(i-1==0){ + cat(mod$F1[i]) + } else{ + if(mod$F1[i]>0) cat(" + ") else cat("- ") + + if(!(abs(mod$F1[i])==1)) cat(abs(mod$F1[i])) + cat("q^{-",i-1,"}",sep="") + } + cat("\t") } - cat("\t") } }
\ No newline at end of file |