From: <par...@us...> - 2012-05-06 20:17:49
|
Revision: 10369 http://octave.svn.sourceforge.net/octave/?rev=10369&view=rev Author: paramaniac Date: 2012-05-06 20:17:43 +0000 (Sun, 06 May 2012) Log Message: ----------- control: fix display of transfer function variable z^-1 Modified Paths: -------------- trunk/octave-forge/main/control/inst/filt.m trunk/octave-forge/main/control/inst/tfpoly2str.m Modified: trunk/octave-forge/main/control/inst/filt.m =================================================================== --- trunk/octave-forge/main/control/inst/filt.m 2012-05-06 19:36:54 UTC (rev 10368) +++ trunk/octave-forge/main/control/inst/filt.m 2012-05-06 20:17:43 UTC (rev 10369) @@ -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. Modified: trunk/octave-forge/main/control/inst/tfpoly2str.m =================================================================== --- trunk/octave-forge/main/control/inst/tfpoly2str.m 2012-05-06 19:36:54 UTC (rev 10368) +++ trunk/octave-forge/main/control/inst/tfpoly2str.m 2012-05-06 20:17:43 UTC (rev 10369) @@ -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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |