summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuraj Yerramilli2015-06-06 00:46:01 +0530
committerSuraj Yerramilli2015-06-06 00:46:01 +0530
commit9044493a051de8cd30cc22123dc851da0aa87349 (patch)
tree7f22ebd0665d78e7adf4ffe0184406bf54f4158e
parentcb696cfcc830e10b6518cf1d768884e967bc84b3 (diff)
downloadSysID-R-code-9044493a051de8cd30cc22123dc851da0aa87349.tar.gz
SysID-R-code-9044493a051de8cd30cc22123dc851da0aa87349.tar.bz2
SysID-R-code-9044493a051de8cd30cc22123dc851da0aa87349.zip
Corrected errors in code
-rw-r--r--R/sim.R13
1 files changed, 7 insertions, 6 deletions
diff --git a/R/sim.R b/R/sim.R
index 1213ecd..2266a40 100644
--- a/R/sim.R
+++ b/R/sim.R
@@ -4,17 +4,18 @@ sim <- function(x) useMethod("sim")
#' @export
sim.arx <- function(model,input,sigma=0){
na <- length(model$A) - 1; nk <- model$ioDelay;
- nb <- length(model$B) - nk
- n <- max(na,nb+nk)
+ nb <- length(model$B) - nk; nb1 <- nb+nk
+ n <- max(na,nb1)
+ coef <- matrix(c(model$A[-1],model$B),nrow=na+nb1)
- y <- matrix(rep(0,length(input)+n),nrow=n)
- u <- matrix(c(rep(0,n),input),nrow=n)
+ y <- rep(0,length(input)+n)
+ u <- c(rep(0,n),input)
# padLeftZeros <- function(x) c(rep(0,n),x)
# u <- apply(input,2,padLeftZeros)
for(i in n+1:length(input)){
- reg <- cbind(-y[i-1:na,],u[i-nk:nb1,])
+ reg <- matrix(c(-(y[i-1:na]),u[i-nk:nb1]),ncol=na+nb1)
y[i] <- reg%*%coef + rnorm(1,sd = sigma)
}
- return(y[n+1:length(input),,drop=F])
+ return(y[n+1:length(input)])
} \ No newline at end of file