Mercurial > forge
changeset 10183:c6e431abdd74 octave-forge
control: fix display of transfer function variable z^-1
author | paramaniac |
---|---|
date | Sun, 06 May 2012 20:17:43 +0000 |
parents | 3d361bf5be76 |
children | 07c4192bcdc2 |
files | main/control/inst/filt.m main/control/inst/tfpoly2str.m |
diffstat | 2 files changed, 26 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/main/control/inst/filt.m Sun May 06 19:36:54 2012 +0000 +++ b/main/control/inst/filt.m Sun May 06 20:17:43 2012 +0000 @@ -57,9 +57,9 @@ ## ## Transfer function 'H' from input 'u1' to output ... ## -## 3 z -## y1: ------------- -## z^2 + 4 z + 2 +## 3 z^-1 +## y1: ------------------- +## 1 + 4 z^-1 + 2 z^-2 ## ## Sampling time: unspecified ## Discrete-time model.
--- a/main/control/inst/tfpoly2str.m Sun May 06 19:36:54 2012 +0000 +++ b/main/control/inst/tfpoly2str.m Sun May 06 20:17:43 2012 +0000 @@ -27,13 +27,21 @@ function str = tfpoly2str (p, tfvar = "x") + ## TODO: simplify this ugly code + str = ""; lp = numel (p); - if (lp > 0) - ## first element (lowest order 0) - a = p(1); + if (lp > 0) # first element (lowest order) + idx = find (p); # first non-zero element + if (isempty (idx)) + str = "0"; + return; + else + idx = idx(1); + endif + a = p(idx); if (a < 0) cs = "-"; @@ -41,11 +49,18 @@ cs = ""; endif - str = [cs, num2str(abs (a), 4)]; + if (idx == 1) + str = [cs, num2str(abs (a), 4)]; + else + if (abs (a) == 1) + str = [cs, __variable__(tfvar, idx-1)]; + else + str = [cs, __coefficient__(a), " ", __variable__(tfvar, idx-1)]; + endif + endif - if (lp > 1) - ## remaining elements of higher order - for k = 2 : lp + if (lp > idx) # remaining elements of higher order + for k = idx+1 : lp a = p(k); if (a != 0) @@ -84,6 +99,6 @@ function str = __variable__ (tfvar, n) - str = [tfvar, "^-", num2str(n)]; + str = [tfvar, "^-", num2str(n)]; endfunction