summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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