diff options
author | Suraj Yerramilli | 2015-03-22 00:00:54 +0530 |
---|---|---|
committer | Suraj Yerramilli | 2015-03-22 00:00:54 +0530 |
commit | bbb54481dee34289f132a6c8960da996525f2319 (patch) | |
tree | 1667b0e31a38d8f8ec38061a94fcedf894ae1d71 | |
parent | aa8d6a9fa5c020a2988a370150624f403121c939 (diff) | |
download | SysID-R-code-bbb54481dee34289f132a6c8960da996525f2319.tar.gz SysID-R-code-bbb54481dee34289f132a6c8960da996525f2319.tar.bz2 SysID-R-code-bbb54481dee34289f132a6c8960da996525f2319.zip |
Added basic print function
-rw-r--r-- | R/tf.R | 29 |
1 files changed, 26 insertions, 3 deletions
@@ -1,4 +1,4 @@ -# S3 class for defining trasnfer functions +# S3 class for defining transfer functions tf <- function(num=c(1),den=c(1),Ts=1){ out <- list(num=num,den=den,Ts=Ts) class(out) <- "tf" @@ -6,7 +6,30 @@ tf <- function(num=c(1),den=c(1),Ts=1){ } # Display the Transfer Function -print.tf <- function(G){ - +print.tf <- function(G){ + cat("Transfer Function \nG(q^{-1}) = B(q^{-1})/A(q^{-1}) \n\n") + cat("A(q^{-1}) = ") + for(i in seq_along(G$den)){ + if(i-1==0){ + cat(G$den[i]) + } else{ + if(G$den[i]>0) + cat("+") + cat(G$den[i],"q^{-",i-1,"}",sep="") + } + cat("\t") + } + cat("\n") + cat("B(q^{-1}) = ") + for(i in seq_along(G$num)){ + if(i-1==0){ + cat(G$num[i]) + } else{ + if(G$num[i]>0) + cat("+") + cat(G$num[i],"q^{-",i-1,"}",sep="") + } + cat("\t") + } } |