diff options
author | Suraj Yerramilli | 2015-06-09 13:21:42 +0530 |
---|---|---|
committer | Suraj Yerramilli | 2015-06-09 13:21:42 +0530 |
commit | 33ece56a477dfe21ea6007320298cfd0684a9adb (patch) | |
tree | cdf837da112a8a17e65d14304ed47871e0e4f059 | |
parent | 1108f50ab77bc71f118022f305ef99abff9749c9 (diff) | |
download | SysID-R-code-33ece56a477dfe21ea6007320298cfd0684a9adb.tar.gz SysID-R-code-33ece56a477dfe21ea6007320298cfd0684a9adb.tar.bz2 SysID-R-code-33ece56a477dfe21ea6007320298cfd0684a9adb.zip |
Corrections in the sim.arx routine
-rw-r--r-- | R/sim.R | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -35,12 +35,12 @@ sim.arx <- function(model,input,sigma=0,seed=NULL){ na <- length(model$A) - 1; nk <- model$ioDelay; nb <- length(model$B) - 1; nb1 <- nb+nk n <- max(na,nb1) - coef <- matrix(c(model$A[-1],model$B),nrow=na+nb1) + coef <- matrix(c(model$A[-1],model$B),nrow=na+(nb+1)) if(class(input)=="idframe"){ - uk <- input$input[,1] + uk <- input$input[,1,drop=T] } else if(class(input) %in% c("matrix","data.frame")){ - uk <- input[,1] + uk <- input[,1,drop=T] } else if(is.numeric(input)){ uk <- input } @@ -50,16 +50,16 @@ sim.arx <- function(model,input,sigma=0,seed=NULL){ if(!is.null(seed)) set.seed(seed) - ek <- rnorm(length(input),sd=sigma) + ek <- rnorm(length(uk),sd=sigma) # padLeftZeros <- function(x) c(rep(0,n),x) # u <- apply(input,2,padLeftZeros) - for(i in n+1:length(input)){ - if(nk==0) v <- u[i-0:(nb-1)] else v <- u[i-nk:nb1] - reg <- matrix(c(-(y[i-1:na]),v),ncol=na+nb1) + for(i in n+1:length(uk)){ + if(nk==0) v <- u[i-0:nb] else v <- u[i-nk:nb1] + reg <- matrix(c(-(y[i-1:na]),v),ncol=na+(nb+1)) y[i] <- reg%*%coef + ek[i-n] } - return(y[n+1:length(input)]) + return(y[n+1:length(uk)]) } #' Simulate from a Polynomial Model |