From: <par...@us...> - 2010-09-15 22:34:59
|
Revision: 7734 http://octave.svn.sourceforge.net/octave/?rev=7734&view=rev Author: paramaniac Date: 2010-09-15 22:34:50 +0000 (Wed, 15 Sep 2010) Log Message: ----------- control: add descriptor state-space models (experimental) Modified Paths: -------------- trunk/octave-forge/main/control/inst/@lti/set.m trunk/octave-forge/main/control/inst/@ss/__get__.m trunk/octave-forge/main/control/inst/@ss/__pole__.m trunk/octave-forge/main/control/inst/@ss/__property_names__.m trunk/octave-forge/main/control/inst/@ss/__set__.m trunk/octave-forge/main/control/inst/@ss/__transpose__.m trunk/octave-forge/main/control/inst/@ss/display.m trunk/octave-forge/main/control/inst/@ss/ss.m trunk/octave-forge/main/control/inst/@tf/__set__.m trunk/octave-forge/main/control/inst/__ss_dim__.m Added Paths: ----------- trunk/octave-forge/main/control/inst/dss.m Modified: trunk/octave-forge/main/control/inst/@lti/set.m =================================================================== --- trunk/octave-forge/main/control/inst/@lti/set.m 2010-09-15 20:07:18 UTC (rev 7733) +++ trunk/octave-forge/main/control/inst/@lti/set.m 2010-09-15 22:34:50 UTC (rev 7734) @@ -43,7 +43,7 @@ elseif (nargout == 0) # set (sys, "prop1", val1, ...) - warning ("lti: get: use sys = get (sys, ""property1"", ...) to save changes"); + warning ("lti: set: use sys = get (sys, ""property1"", ...) to save changes"); warning (" octave does not support pass by reference"); else # sys = set (sys, "prop1", val1, ...) Modified: trunk/octave-forge/main/control/inst/@ss/__get__.m =================================================================== --- trunk/octave-forge/main/control/inst/@ss/__get__.m 2010-09-15 20:07:18 UTC (rev 7733) +++ trunk/octave-forge/main/control/inst/@ss/__get__.m 2010-09-15 22:34:50 UTC (rev 7734) @@ -37,6 +37,9 @@ case "d" val = sys.d; + case "e" + val = sys.e; + case {"stname", "statename"} val = sys.stname; Modified: trunk/octave-forge/main/control/inst/@ss/__pole__.m =================================================================== --- trunk/octave-forge/main/control/inst/@ss/__pole__.m 2010-09-15 20:07:18 UTC (rev 7733) +++ trunk/octave-forge/main/control/inst/@ss/__pole__.m 2010-09-15 22:34:50 UTC (rev 7734) @@ -1,4 +1,4 @@ -## Copyright (C) 2009 Lukas F. Reichlin +## Copyright (C) 2009 - 2010 Lukas F. Reichlin ## ## This file is part of LTI Syncope. ## @@ -20,10 +20,14 @@ ## Author: Lukas Reichlin <luk...@gm...> ## Created: October 2009 -## Version: 0.1 +## Version: 0.2 function pol = __pole__ (sys) - pol = eig (sys.a); + if (isempty (sys.e)) + pol = eig (sys.a); + else + pol = eig (sys.a, sys.e); + endif endfunction \ No newline at end of file Modified: trunk/octave-forge/main/control/inst/@ss/__property_names__.m =================================================================== --- trunk/octave-forge/main/control/inst/@ss/__property_names__.m 2010-09-15 20:07:18 UTC (rev 7733) +++ trunk/octave-forge/main/control/inst/@ss/__property_names__.m 2010-09-15 22:34:50 UTC (rev 7734) @@ -30,6 +30,7 @@ "b"; "c"; "d"; + "e"; "stname"}; ## cell vector of ss-specific assignable values @@ -37,6 +38,7 @@ "n-by-m matrix (m = number of inputs)"; "p-by-n matrix (p = number of outputs)"; "p-by-m matrix"; + "n-by-n matrix"; "n-by-1 cell vector of strings"}; if (nargin == 1) Modified: trunk/octave-forge/main/control/inst/@ss/__set__.m =================================================================== --- trunk/octave-forge/main/control/inst/@ss/__set__.m 2010-09-15 20:07:18 UTC (rev 7733) +++ trunk/octave-forge/main/control/inst/@ss/__set__.m 2010-09-15 22:34:50 UTC (rev 7734) @@ -1,4 +1,4 @@ -## Copyright (C) 2009 Lukas F. Reichlin +## Copyright (C) 2009 - 2010 Lukas F. Reichlin ## ## This file is part of LTI Syncope. ## @@ -20,27 +20,35 @@ ## Author: Lukas Reichlin <luk...@gm...> ## Created: October 2009 -## Version: 0.1 +## Version: 0.2 function sys = __set__ (sys, prop, val) switch (prop) # {<internal name>, <user name>} case "a" - [m, n, p] = __ss_dim__ (val, sys.b, sys.c, sys.d); + __ss_dim__ (val, sys.b, sys.c, sys.d); sys.a = val; case "b" - [m, n, p] = __ss_dim__ (sys.a, val, sys.c, sys.d); + __ss_dim__ (sys.a, val, sys.c, sys.d); sys.b = val; case "c" - [m, n, p] = __ss_dim__ (sys.a, sys.b, val, sys.d); + __ss_dim__ (sys.a, sys.b, val, sys.d); sys.c = val; case "d" - [m, n, p] = __ss_dim__ (sys.a, sys.b, sys.c, val); + __ss_dim__ (sys.a, sys.b, sys.c, val); sys.d = val; + case "e" + if (isempty (e)) + sys.e = []; # avoid [](nx0) or [](0xn) + else + __ss_dim__ (sys.a, sys.b, sys.c, sys.d, val); + sys.e = val; + endif + case {"stname", "statename"} n = rows (sys.a); sys.stname = __check_name_numel__ (val, n); Modified: trunk/octave-forge/main/control/inst/@ss/__transpose__.m =================================================================== --- trunk/octave-forge/main/control/inst/@ss/__transpose__.m 2010-09-15 20:07:18 UTC (rev 7733) +++ trunk/octave-forge/main/control/inst/@ss/__transpose__.m 2010-09-15 22:34:50 UTC (rev 7734) @@ -20,7 +20,7 @@ ## Author: Lukas Reichlin <luk...@gm...> ## Created: February 2010 -## Version: 0.1 +## Version: 0.2 function sys = __transpose__ (sys) @@ -28,6 +28,7 @@ b = sys.b; c = sys.c; d = sys.d; + e = sys.e; sys.stname = repmat ({""}, rows (a), 1); @@ -35,5 +36,6 @@ sys.b = c.'; sys.c = b.'; sys.d = d.'; + sys.e = e.'; endfunction \ No newline at end of file Modified: trunk/octave-forge/main/control/inst/@ss/display.m =================================================================== --- trunk/octave-forge/main/control/inst/@ss/display.m 2010-09-15 20:07:18 UTC (rev 7733) +++ trunk/octave-forge/main/control/inst/@ss/display.m 2010-09-15 22:34:50 UTC (rev 7734) @@ -51,6 +51,10 @@ disp (""); + if (! isempty (sys.e)) + __disp_mat__ (sys.e, [inputname(1), ".e"], stname, stname); + endif + if (! isempty (sys.a)) __disp_mat__ (sys.a, [inputname(1), ".a"], stname, stname); __disp_mat__ (sys.b, [inputname(1), ".b"], stname, inname); Modified: trunk/octave-forge/main/control/inst/@ss/ss.m =================================================================== --- trunk/octave-forge/main/control/inst/@ss/ss.m 2010-09-15 20:07:18 UTC (rev 7733) +++ trunk/octave-forge/main/control/inst/@ss/ss.m 2010-09-15 22:34:50 UTC (rev 7734) @@ -58,6 +58,7 @@ superiorto ("zpk", "tf", "double"); argc = 0; + e = []; switch (nargin) case 0 # ss () @@ -111,6 +112,7 @@ if (isempty (a)) # static system tsam = -1; + a = []; # avoid [](nx0) or [](0xn) endif [m, n, p] = __ss_dim__ (a, b, c, d); @@ -119,6 +121,7 @@ ssdata = struct ("a", a, "b", b, "c", c, "d", d, + "e", e, "stname", {stname}); ltisys = lti (p, m, tsam); Modified: trunk/octave-forge/main/control/inst/@tf/__set__.m =================================================================== --- trunk/octave-forge/main/control/inst/@tf/__set__.m 2010-09-15 20:07:18 UTC (rev 7733) +++ trunk/octave-forge/main/control/inst/@tf/__set__.m 2010-09-15 22:34:50 UTC (rev 7734) @@ -27,12 +27,12 @@ switch (prop) # {<internal name>, <user name>} case "num" num = __vec2tfpoly__ (val); - [p, m] = __tf_dim__ (num, sys.den); + __tf_dim__ (num, sys.den); sys.num = num; case "den" den = __vec2tfpoly__ (val); - [p, m] = __tf_dim__ (sys.num, den); + __tf_dim__ (sys.num, den); sys.den = den; case {"tfvar", "variable"} Modified: trunk/octave-forge/main/control/inst/__ss_dim__.m =================================================================== --- trunk/octave-forge/main/control/inst/__ss_dim__.m 2010-09-15 20:07:18 UTC (rev 7733) +++ trunk/octave-forge/main/control/inst/__ss_dim__.m 2010-09-15 22:34:50 UTC (rev 7734) @@ -1,4 +1,4 @@ -## Copyright (C) 2009 Lukas F. Reichlin +## Copyright (C) 2009 - 2010 Lukas F. Reichlin ## ## This file is part of LTI Syncope. ## @@ -23,8 +23,16 @@ ## Created: September 2009 ## Version: 0.2 -function [m, n, p] = __ss_dim__ (a, b, c, d) +function [m, n, p] = __ss_dim__ (a, b, c, d, e = []) + if (! all ([isreal(a), isreal(b), isreal(c), isreal(d), isreal(e)])) + error ("ss: system matrices must be real"); + endif + + if (! all ([ndims(a), ndims(b), ndims(c), ndims(d), ndims(e)] == 2)) + error ("ss: system matrices must be two-dimensional arrays"); + endif + [arows, acols] = size (a); [brows, bcols] = size (b); [crows, ccols] = size (c); @@ -34,7 +42,7 @@ n = arows; # = acols p = crows; # = drows - if (! issquare (a) && ! isempty (a)) + if (arows != acols) error ("ss: system matrix a(%dx%d) is not square", arows, acols); endif @@ -58,8 +66,9 @@ crows, ccols, drows, dcols); endif - if (! isreal (a) || ! isreal (b) || ! isreal (c) || ! isreal (d)) - error ("ss: system matrices are not real"); + if (! isempty (e) && any (size (e) != n)) + error ("ss: system matrices a(%dx%d) and e(%dx%d) are incompatible", + arows, acols, rows (e), columns (e)); endif endfunction Added: trunk/octave-forge/main/control/inst/dss.m =================================================================== --- trunk/octave-forge/main/control/inst/dss.m (rev 0) +++ trunk/octave-forge/main/control/inst/dss.m 2010-09-15 22:34:50 UTC (rev 7734) @@ -0,0 +1,68 @@ +## Copyright (C) 2010 Lukas F. Reichlin +## +## This file is part of LTI Syncope. +## +## LTI Syncope is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## LTI Syncope is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{sys} =} dss (@var{sys}) +## @deftypefnx {Function File} {@var{sys} =} dss (@var{d}) +## @deftypefnx {Function File} {@var{sys} =} dss (@var{a}, @var{b}, @var{c}, @var{d}, @var{e}) +## @deftypefnx {Function File} {@var{sys} =} dss (@var{a}, @var{b}, @var{c}, @var{d}, @var{e}, @var{tsam}) +## Create or convert to state-space model. +## +## @strong{Inputs} +## @table @var +## @item a +## State transition matrix. +## @item b +## Input matrix. +## @item c +## Measurement matrix. +## @item d +## Feedthrough matrix. +## @item e +## Descriptor matrix. +## @item tsam +## Sampling time. If @var{tsam} is not specified, a continuous-time +## model is assumed. +## @end table +## +## @strong{Outputs} +## @table @var +## @item sys +## Descriptor state-space model. +## @end table +## +## @seealso{ss} +## @end deftypefn + +## Author: Lukas Reichlin <luk...@gm...> +## Created: September 2010 +## Version: 0.1 + +function sys = dss (varargin) + + switch (nargin) + case {0, 2, 3, 4} + print_usage (); + + case 1 # static gain + sys = ss (varargin{1}); + + otherwise # general case + sys = ss (varargin{[1:4, 6:end]}, "e", varargin{5}); + endswitch + +endfunction \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |