From: <par...@us...> - 2010-08-31 13:34:57
|
Revision: 7614 http://octave.svn.sourceforge.net/octave/?rev=7614&view=rev Author: paramaniac Date: 2010-08-31 13:06:08 +0000 (Tue, 31 Aug 2010) Log Message: ----------- control: improve error checking Modified Paths: -------------- trunk/octave-forge/main/control/inst/@lti/set.m trunk/octave-forge/main/control/inst/@ss/ss.m trunk/octave-forge/main/control/inst/@tf/tf.m trunk/octave-forge/main/control/inst/__ssmatdim__.m trunk/octave-forge/main/control/inst/gensig.m trunk/octave-forge/main/control/inst/issample.m Modified: trunk/octave-forge/main/control/inst/@lti/set.m =================================================================== --- trunk/octave-forge/main/control/inst/@lti/set.m 2010-08-31 00:36:50 UTC (rev 7613) +++ trunk/octave-forge/main/control/inst/@lti/set.m 2010-08-31 13:06:08 UTC (rev 7614) @@ -47,9 +47,7 @@ else # sys = set (sys, "prop1", val1, ...) - n = (nargin-1) / 2; - - if (n != round (n)) + if (rem (nargin-1, 2)) error ("lti: set: properties and values must come in pairs"); endif @@ -79,7 +77,6 @@ otherwise sys = __set__ (sys, prop, val); - endswitch endfor Modified: trunk/octave-forge/main/control/inst/@ss/ss.m =================================================================== --- trunk/octave-forge/main/control/inst/@ss/ss.m 2010-08-31 00:36:50 UTC (rev 7613) +++ trunk/octave-forge/main/control/inst/@ss/ss.m 2010-08-31 13:06:08 UTC (rev 7614) @@ -1,4 +1,4 @@ -## Copyright (C) 2009 Lukas F. Reichlin +## Copyright (C) 2009 - 2010 Lukas F. Reichlin ## ## This file is part of LTI Syncope. ## @@ -25,9 +25,9 @@ ## Author: Lukas Reichlin <luk...@gm...> ## Created: September 2009 -## Version: 0.1 +## Version: 0.2 -function sys = ss (a, b, c, d, varargin) +function sys = ss (a = [], b = [], c = [], d = [], varargin) ## model precedence: frd > ss > zpk > tf > double %inferiorto ("frd"); @@ -36,12 +36,8 @@ argc = 0; switch (nargin) - case 0 - a = []; - b = []; - c = []; - d = []; - tsam = -1; + case 0 # ss () + ## tsam = -1; # noting is done here, but "case 0" needed to prevent "otherwise" case 1 if (isa (a, "ss")) # already in ss form @@ -56,7 +52,7 @@ a = []; b = zeros (0, columns (d)); c = zeros (rows (d), 0); - tsam = -1; + ## tsam = -1; else print_usage (); endif @@ -64,13 +60,13 @@ case 2 print_usage (); - case 3 # a, b, c without d + case 3 # a, b, c without d ss (a, b, c) d = zeros (rows (c), columns (b)); tsam = 0; - case 4 # continuous system - tsam = 0; + case 4 # continuous system ss (a, b, c, d), ss ([], [], [], d) [b, c] = __gaincheck__ (b, c, d); + tsam = 0; otherwise # default case [b, c] = __gaincheck__ (b, c, d); @@ -79,7 +75,6 @@ if (issample (varargin{1}, 1)) # sys = ss (a, b, c, d, tsam, "prop1, "val1", ...) tsam = varargin{1}; argc--; - if (argc > 0) varargin = varargin(2:end); endif @@ -94,17 +89,15 @@ tsam = -1; endif - [nu, nx, ny] = __ssmatdim__ (a, b, c, d); + [m, n, p] = __ssmatdim__ (a, b, c, d); - stname = repmat ({""}, nx, 1); + stname = repmat ({""}, n, 1); - ssdata = struct ("a", a, - "b", b, - "c", c, - "d", d, + ssdata = struct ("a", a, "b", b, + "c", c, "d", d, "stname", {stname}); - ltisys = lti (ny, nu, tsam); + ltisys = lti (p, m, tsam); sys = class (ssdata, "ss", ltisys); @@ -118,6 +111,7 @@ function [b, c] = __gaincheck__ (b, c, d) ## catch the case sys = ss ([], [], [], d) + ## don't forget to set tsam = -1 if (isempty (b) && isempty (c)) b = zeros (0, columns (d)); c = zeros (rows(d), 0); Modified: trunk/octave-forge/main/control/inst/@tf/tf.m =================================================================== --- trunk/octave-forge/main/control/inst/@tf/tf.m 2010-08-31 00:36:50 UTC (rev 7613) +++ trunk/octave-forge/main/control/inst/@tf/tf.m 2010-08-31 13:06:08 UTC (rev 7614) @@ -1,4 +1,4 @@ -## Copyright (C) 2009 Lukas F. Reichlin +## Copyright (C) 2009 - 2010 Lukas F. Reichlin ## ## This file is part of LTI Syncope. ## @@ -25,9 +25,9 @@ ## Author: Lukas Reichlin <luk...@gm...> ## Created: September 2009 -## Version: 0.1 +## Version: 0.2 -function sys = tf (num, den, varargin) +function sys = tf (num = {}, den = {}, varargin) ## model precedence: frd > ss > zpk > tf > double %inferiorto ("frd", "ss", "zpk"); # error if de-commented. bug in octave? @@ -37,8 +37,6 @@ switch (nargin) case 0 - num = {}; - den = {}; tsam = -1; tfvar = "x"; # undefined Modified: trunk/octave-forge/main/control/inst/__ssmatdim__.m =================================================================== --- trunk/octave-forge/main/control/inst/__ssmatdim__.m 2010-08-31 00:36:50 UTC (rev 7613) +++ trunk/octave-forge/main/control/inst/__ssmatdim__.m 2010-08-31 13:06:08 UTC (rev 7614) @@ -16,23 +16,23 @@ ## along with this program. If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## Number of inputs, states and outputs of state space matrices. +## Number of inputs (m), states (n) and outputs (p) of state space matrices. ## For internal use only. ## Author: Lukas Reichlin <luk...@gm...> ## Created: September 2009 ## Version: 0.1 -function [nu, nx, ny] = __ssmatdim__ (a, b, c, d) +function [m, n, p] = __ssmatdim__ (a, b, c, d) [arows, acols] = size (a); [brows, bcols] = size (b); [crows, ccols] = size (c); [drows, dcols] = size (d); - nu = bcols; # = dcols - nx = arows; # = acols - ny = crows; # = drows + m = bcols; # = dcols + n = arows; # = acols + p = crows; # = drows if (! issquare (a) && ! isempty (a)) error ("ss: system matrix a(%dx%d) is not square", arows, acols); Modified: trunk/octave-forge/main/control/inst/gensig.m =================================================================== --- trunk/octave-forge/main/control/inst/gensig.m 2010-08-31 00:36:50 UTC (rev 7613) +++ trunk/octave-forge/main/control/inst/gensig.m 2010-08-31 13:06:08 UTC (rev 7614) @@ -1,4 +1,4 @@ -## Copyright (C) 2009 Lukas F. Reichlin +## Copyright (C) 2009 - 2010 Lukas F. Reichlin ## ## This file is part of LTI Syncope. ## @@ -52,7 +52,7 @@ ## Author: Lukas Reichlin <luk...@gm...> ## Created: August 2009 -## Version: 0.1 +## Version: 0.2 function [u, t] = gensig (sigtype, tau, tfinal, tsam) @@ -64,12 +64,20 @@ error ("gensig: first argument must be a string"); endif + if (! issample (tau)) + error ("gensig: second argument is not a valid period"); + endif + if (nargin < 3) tfinal = 5 * tau; + elseif (! issample (tfinal)) + error ("gensig: third argument is not a valid final time"); endif if (nargin < 4) tsam = tau / 64; + elseif (! issample (tsam)) + error ("gensig: fourth argument is not a valid sampling time"); endif t = (0 : tsam : tfinal).'; @@ -84,7 +92,7 @@ case "pu" u = rem (t, tau) < (1 - 1000*eps) * tsam; otherwise - error ("gensig: invalid signal type"); + error ("gensig: ""%s"" is an invalid signal type", sigtype); endswitch endfunction Modified: trunk/octave-forge/main/control/inst/issample.m =================================================================== --- trunk/octave-forge/main/control/inst/issample.m 2010-08-31 00:36:50 UTC (rev 7613) +++ trunk/octave-forge/main/control/inst/issample.m 2010-08-31 13:06:08 UTC (rev 7614) @@ -16,8 +16,10 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} issample (@var{ts}) +## @deftypefnx {Function File} {} issample (@var{ts}, @var{-1}) ## Return true if @var{ts} is a valid sampling time -## (real, scalar, > 0). +## (real, scalar, > 0). If a second argument != 0 +## is passed, -1 becomes a valid sample time as well. ## @end deftypefn ## Author: A. S. Hodel <a.s...@en...> @@ -25,7 +27,7 @@ ## Adapted-By: Lukas Reichlin <luk...@gm...> ## Date: September 2009 -## Version: 0.1 +## Version: 0.2 function bool = issample (tsam, flg = 0) @@ -34,9 +36,9 @@ endif if (flg) - bool = (isscalar (tsam) && (tsam >= 0 || tsam == -1)); + bool = (isnumeric (tsam) && isscalar (tsam) && (tsam >= 0 || tsam == -1)); else - bool = (isscalar (tsam) && (tsam == abs (tsam)) && (tsam != 0)); + bool = (isnumeric (tsam) && isscalar (tsam) && (tsam == abs (tsam)) && (tsam != 0)); endif endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |