Mercurial > hg > octave-nkf
changeset 4462:3e48e60a1f8b
[project @ 2003-07-12 03:31:41 by jwe]
line wrap: on
line diff
--- a/scripts/control/base/dgram.m +++ b/scripts/control/base/dgram.m @@ -44,6 +44,7 @@ function m = dgram (a, b) ## let dlyap do the error checking... - m = dlyap(a,b*b'); + + m = dlyap (a, b*b'); endfunction
--- a/scripts/control/base/freqchkw.m +++ b/scripts/control/base/freqchkw.m @@ -28,16 +28,16 @@ function USEW = freqchkw (w) - if(isempty(w)) + if (isempty (w)) USEW = 0; - elseif(!isvector(w)) - error(["w (",num2str(rows(w)),"x",num2str(columns(w)), ... - "): must be [], a vector or a scalar"]); - elseif( (max(abs(imag(w))) != 0) && (min(real(w)) <= 0) ) - error("w must have real positive entries"); + elseif (! isvector (w)) + error ("w (%dx%d): must be [], a vector or a scalar", + rows (w), columns (w)); + elseif (max (abs (imag(w))) != 0 && min (real (w)) <= 0) + error ("w must have real positive entries"); else - w = sort(w); - USEW = 1; # vector provided (check values later) + w = sort (w); + USEW = 1; ## vector provided (check values later) endif endfunction
--- a/scripts/control/base/gram.m +++ b/scripts/control/base/gram.m @@ -28,7 +28,8 @@ function m = gram (a, b) - ## let lyap do the error checking... - m = lyap(a,b*b'); + ## Let lyap do the error checking... + + m = lyap (a, b*b'); endfunction
--- a/scripts/control/system/__abcddims__.m +++ b/scripts/control/system/__abcddims__.m @@ -30,9 +30,9 @@ function [y, my, ny] = __abcddims__ (x) y = x; - if(isempty(y)) + if (isempty (y)) y = []; endif - [my,ny] = size(y); + [my, ny] = size (y); endfunction
--- a/scripts/control/system/__sysdefstname__.m +++ b/scripts/control/system/__sysdefstname__.m @@ -25,17 +25,17 @@ function stname = __sysdefstname__ (n, nz) - stname = list(); - if(n > 0) + stname = list (); + if (n > 0) for ii = 1:n - stname(ii) = sprintf("x_%d",ii); + stname(ii) = sprintf ("x_%d", ii); endfor endif ## Set default names for discrete states - if(nz > 0) + if (nz > 0) for ii = (n+1):(n+nz) - stname(ii) = sprintf("xd_%d",ii); + stname(ii) = sprintf ("xd_%d", ii); endfor endif
--- a/scripts/control/system/__tf2sysl__.m +++ b/scripts/control/system/__tf2sysl__.m @@ -24,12 +24,12 @@ function vec = __tf2sysl__ (vec) - while( (length(vec) > 1) & (vec(1) == 0) ) - vec = vec(2:length(vec)); + while (length (vec) > 1 && vec(1) == 0) + vec = vec (2:end); endwhile - if(vec(1) == 0) - warning("tf2sys: polynomial has no nonzero coefficients!") + if (vec(1) == 0) + warning ("tf2sys: polynomial has no nonzero coefficients!") endif endfunction
--- a/scripts/control/system/is_sample.m +++ b/scripts/control/system/is_sample.m @@ -27,6 +27,6 @@ function out = is_sample (Ts) - out = (isscalar(Ts) && (Ts == abs(Ts)) && (Ts != 0) ); + out = (isscalar (Ts) && (Ts == abs (Ts)) && (Ts != 0)); endfunction
--- a/scripts/control/system/is_signal_list.m +++ b/scripts/control/system/is_signal_list.m @@ -21,13 +21,13 @@ ## Return true if @var{mylist} is a list of individual strings. ## @end deftypefn -function flg = is_signal_list(mylist) +function flg = is_signal_list (mylist) - flg = islist(mylist); + flg = islist (mylist); if (flg) for ii = 1:length (mylist) - if (! (isstr (nth (mylist,ii)) & rows (nth (mylist,ii)) == 1)) + if (! (isstr (nth (mylist, ii)) && rows (nth (mylist,ii)) == 1)) flg = 0; endif endfor
--- a/scripts/control/system/is_siso.m +++ b/scripts/control/system/is_siso.m @@ -27,14 +27,14 @@ function SISO = is_siso (sys) - if(nargin != 1) - usage("SISO = is_siso(sys)"); - elseif( !isstruct(sys)) - error("input must be a system structure (see ss2sys, tf2sys, zp2sys)"); + if (nargin != 1) + usage ("SISO = is_siso (sys)"); + elseif (! isstruct (sys)) + error ("input must be a system structure (see ss2sys, tf2sys, zp2sys)"); endif - [n,nz,m,p] = sysdimensions(sys); + [n, nz, m, p] = sysdimensions (sys); - SISO = (m == 1 & p == 1); + SISO = (m == 1 && p == 1); endfunction
--- a/scripts/control/system/sys2fir.m +++ b/scripts/control/system/sys2fir.m @@ -31,22 +31,23 @@ ## let sys2tf do most of the work - [num,den,tsam,inname,outname] = sys2tf(sys); + [num, den, tsam, inname, outname] = sys2tf (sys); alph = den(1); # scale to get monic denominator - den = den/alph; - num = num/alph; - l = length(den); - m = length(num); - if( norm(den(2:l)) ) - sysout(sys,"tf"); - error("denominator has poles away from origin"); - elseif( !is_digital(sys) ) - error("system must be discrete-time to be FIR"); - elseif(m != l) - warning(["sys2fir: deg(num) - deg(den) = ",num2str(m-l), ... - "; coefficients must be shifted"]); + den /= alph; + num /= alph; + l = length (den); + m = length (num); + if (norm (den(2:l))) + sysout (sys, "tf"); + error ("denominator has poles away from origin"); + elseif (! is_digital (sys)) + error ("system must be discrete-time to be FIR"); + elseif (m != l) + warning ("sys2fir: deg(num) - deg(den) = %d; coefficients must be shifted", + m-l); endif c = num; + endfunction
--- a/scripts/control/system/syschtsam.m +++ b/scripts/control/system/syschtsam.m @@ -28,20 +28,20 @@ function retsys = syschtsam (sys, tsam) if (nargin != 2) - usage("retsys = syschtsam(sys,tsam)"); - elseif (!isstruct(sys)) - error("sys must be in system data structure form"); - elseif(!isscalar(tsam)) - disp("syschtsam:") + usage ("retsys = syschtsam (sys, tsam)"); + elseif (! isstruct (sys)) + error ("sys must be in system data structure form"); + elseif (! isscalar (tsam)) + disp ("syschtsam:") tsam - error("tsam must be a scalar") - elseif ( ! (is_sample(tsam) | (tsam == 0) ) ) - error("tsam must be real, scalar, and greater than zero"); - elseif (sysgettsam(sys) == 0) - [nc,nz,mm,pp] = sysdimensions(sys); - warning("syschtsam: continuous system (nc=%d, nz=%d, mm=%d, pp=%d)", ... - nc,nz,mm,pp); - warning("syschtsam: The system is continuous, use c2d to make the system discrete"); + error ("tsam must be a scalar") + elseif (! (is_sample (tsam) || tsam <= 0)) + error ("tsam must be real, scalar, and greater than zero"); + elseif (sysgettsam (sys) == 0) + [nc, nz, mm, pp] = sysdimensions (sys); + warning ("syschtsam: continuous system (nc=%d, nz=%d, mm=%d, pp=%d)", + nc, nz, mm, pp); + warning ("syschtsam: The system is continuous, use c2d to make the system discrete"); endif retsys = sys;
--- a/scripts/control/system/sysgettsam.m +++ b/scripts/control/system/sysgettsam.m @@ -23,8 +23,8 @@ function T = sysgettsam (sys) - if(!isstruct(sys)) - usage("T = sysgettsam(sys)"); + if (! isstruct (sys)) + usage ("T = sysgettsam (sys)"); endif T = sys.tsam;
--- a/scripts/control/system/sysgettype.m +++ b/scripts/control/system/sysgettype.m @@ -33,10 +33,11 @@ function systype = sysgettype (sys) - if(!isstruct(sys)) - error("sysgettype: input sys is not a structure"); + if (! isstruct (sys)) + error ("sysgettype: input sys is not a structure"); endif - typestr = list("tf","zp","ss"); - systype = nth(typestr,sys.sys(1) + 1); + typestr = list ("tf", "zp", "ss"); + systype = nth (typestr, sys.sys(1) + 1); + endfunction
--- a/scripts/control/system/tf2zp.m +++ b/scripts/control/system/tf2zp.m @@ -28,15 +28,23 @@ function [zer, pol, k] = tf2zp (num, den) - if(nargin == 2) - if(length(den) > 1) pol = roots(den); - else pol=[]; endif - if(length(num) > 1) zer = roots(num); - else zer=[]; endif - else error("Incorrect number of input arguments"); + if (nargin == 2) + if (length (den) > 1) + pol = roots (den); + else + pol = []; + endif + + if (length (num) > 1) + zer = roots (num); + else + zer = []; + endif + else + error ("Incorrect number of input arguments"); endif - [a,b,c,d] = tf2ss(num,den); - [dum,k] = tzero(a,b,c,d); + [a, b, c, d] = tf2ss (num, den); + [dum, k] = tzero (a, b, c, d); endfunction
--- a/scripts/control/system/ugain.m +++ b/scripts/control/system/ugain.m @@ -31,9 +31,9 @@ function outsys = ugain (n) - if((nargin != 1) || (nargout > 1)) - usage("outsys = ugain(n)") + if (nargin != 1 || nargout > 1) + usage ("outsys = ugain(n)"); endif - outsys = ss2sys([],[],[],eye(n)); + outsys = ss2sys ([], [], [], eye (n)); endfunction
--- a/scripts/control/util/prompt.m +++ b/scripts/control/util/prompt.m @@ -31,16 +31,16 @@ function prompt (str) - if(nargin > 1) - usage("prompt([str])"); - elseif(nargin == 0) + if (nargin > 1) + usage ("prompt ([str])"); + elseif (nargin == 0) str = "\n ---- Press a key to continue ---"; - elseif ( !isstr(str) ) - error("prompt: input must be a string"); + elseif (! isstr (str) ) + error ("prompt: input must be a string"); endif - disp(str); - fflush(stdout); - kbhit; + disp (str); + fflush (stdout); + kbhit (); endfunction
--- a/scripts/control/util/run_cmd.m +++ b/scripts/control/util/run_cmd.m @@ -19,12 +19,12 @@ ## run_cmd: short script used in demos ## prints string cmd to the screen, then executes after a pause -disp(["Command: ",cmd]) -puts("Press a key to execute command"); -fflush(stdout); -kbhit(); -disp(" executing"); -fflush(stdout); -eval(cmd); -disp("---") -disp(" ") +disp (["Command: ", cmd]) +puts ("Press a key to execute command"); +fflush (stdout); +kbhit (); +disp (" executing"); +fflush (stdout); +eval (cmd); +disp ("---") +disp (" ")
--- a/scripts/control/util/zgrownorm.m +++ b/scripts/control/util/zgrownorm.m @@ -26,11 +26,11 @@ function [sig, tau] = zgrownorm (mat, meps) rownorm = []; - for ii=1:rows(mat) - rownorm(ii) = norm(mat(ii,:)); + for ii = 1:rows (mat) + rownorm(ii) = norm (mat(ii,:)); endfor - sig = sum(rownorm > meps); - tau = sum(rownorm <= meps); + sig = sum (rownorm > meps); + tau = sum (rownorm <= meps); endfunction
--- a/scripts/control/util/zgshsr.m +++ b/scripts/control/util/zgshsr.m @@ -29,17 +29,18 @@ function x = zgshsr (y) - if(!isvector(y)) - error(sprintf("y(%dx%d) must be a vector",rows(y),columns(y))); + if (! isvector (y)) + error (sprintf ("y(%dx%d) must be a vector", rows (y), columns (y))); endif - x = vec(y); - m = length(x); - if (m>1) - beta = (1 + sqrt(m))*x(1) + sum(x(2:m)); - beta = beta/(m+sqrt(m)); - x(1) = x(1) - beta*(1.0d0+sqrt(m)); - x(2:m) = x(2:m) - beta*ones(m-1,1); + x = vec (y); + m = length (x); + if (m > 1) + beta = (1 + sqrt (m)) * x(1) + sum (x(2:m)); + beta /= (m + sqrt (m)); + x(1) -= (beta * (1 + sqrt (m))); + x(2:m) -= (beta * ones (m-1,1)); else x = -x; endif + endfunction