summaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
authorSuraj Yerramilli2015-11-02 10:56:37 +0530
committerSuraj Yerramilli2015-11-02 10:56:37 +0530
commitd8afcfb5b0a246b4f4eacd130aa72f254cae3e05 (patch)
tree4dfb85428b52909980016cf3f4c6ec65d3b97d26 /R
parenta11378e90b61dd1bfc5338c2300d2973ad00bcbd (diff)
downloadSysID-R-code-d8afcfb5b0a246b4f4eacd130aa72f254cae3e05.tar.gz
SysID-R-code-d8afcfb5b0a246b4f4eacd130aa72f254cae3e05.tar.bz2
SysID-R-code-d8afcfb5b0a246b4f4eacd130aa72f254cae3e05.zip
Removing repetitions
Diffstat (limited to 'R')
-rw-r--r--R/poly.R173
1 files changed, 73 insertions, 100 deletions
diff --git a/R/poly.R b/R/poly.R
index 122f4c7..341f1a0 100644
--- a/R/poly.R
+++ b/R/poly.R
@@ -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