From a54aef7be7f1db6aca3588719832751dd4ce00d7 Mon Sep 17 00:00:00 2001 From: Suraj Yerramilli Date: Sat, 6 Jun 2015 00:18:37 +0530 Subject: Added simulation method --- R/sim.R | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/R/sim.R b/R/sim.R index a30cc85..5224b61 100644 --- a/R/sim.R +++ b/R/sim.R @@ -1,2 +1,20 @@ #' @export -sim <- function(x) useMethod("sim") \ No newline at end of file +sim <- function(x) useMethod("sim") + +#' @export +sim.arx <- function(model,input){ + na <- length(model$A) - 1; nk <- model$ioDelay; + nb <- length(model$B) - nk + n <- max(na,nb+nk) + + y <- matrix(rep(0,length(input)+n),nrow=n) + u <- matrix(c(rep(0,n),input),nrow=n) + # 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,]) + y[i] <- reg%*%coef + } + return(y[n+1:length(input),,drop=F]) +} \ No newline at end of file -- cgit