summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuraj Yerramilli2015-06-06 00:18:37 +0530
committerSuraj Yerramilli2015-06-06 00:18:37 +0530
commita54aef7be7f1db6aca3588719832751dd4ce00d7 (patch)
tree19af4ebd37a6551761ef57e0d1a26bcb5df4cfcc
parent6771e27e52fbf687260d8df3bb3c8613352bc0d4 (diff)
downloadSysID-R-code-a54aef7be7f1db6aca3588719832751dd4ce00d7.tar.gz
SysID-R-code-a54aef7be7f1db6aca3588719832751dd4ce00d7.tar.bz2
SysID-R-code-a54aef7be7f1db6aca3588719832751dd4ce00d7.zip
Added simulation method
-rw-r--r--R/sim.R20
1 files changed, 19 insertions, 1 deletions
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