From: <par...@us...> - 2010-10-16 21:35:53
|
Revision: 7850 http://octave.svn.sourceforge.net/octave/?rev=7850&view=rev Author: paramaniac Date: 2010-10-16 21:35:46 +0000 (Sat, 16 Oct 2010) Log Message: ----------- control: simplify constructor for state-space models Modified Paths: -------------- trunk/octave-forge/main/control/inst/@ss/ss.m Added Paths: ----------- trunk/octave-forge/main/control/inst/__adjust_ss_data__.m Modified: trunk/octave-forge/main/control/inst/@ss/ss.m =================================================================== --- trunk/octave-forge/main/control/inst/@ss/ss.m 2010-10-16 20:46:18 UTC (rev 7849) +++ trunk/octave-forge/main/control/inst/@ss/ss.m 2010-10-16 21:35:46 UTC (rev 7850) @@ -52,7 +52,7 @@ ## Author: Lukas Reichlin <luk...@gm...> ## Created: September 2009 -## Version: 0.2 +## Version: 0.3 function sys = ss (a = [], b = [], c = [], d = [], varargin) @@ -60,12 +60,13 @@ ## inferiorto ("frd"); superiorto ("zpk", "tf", "double"); - argc = 0; - e = []; + argc = 0; # initialize argument count + tsam = 0; # initialize sampling time switch (nargin) - case 0 # ss () - ## tsam = -1; # nothing is done here, but "case 0" needed to prevent "otherwise" + case {0, 3, 4} # ss (), ss (a, b, c), ss (a, b, c, d) + ## nothing is done here + ## case needed to prevent "otherwise" case 1 if (isa (a, "ss")) # already in ss form @@ -75,12 +76,9 @@ [sys, alti] = __sys2ss__ (a); sys.lti = alti; # preserve lti properties return; - elseif (is_real_matrix (a)) # static gain + elseif (is_real_matrix (a)) # static gain sys = ss (5) d = a; a = []; - b = zeros (0, columns (d)); - c = zeros (rows (d), 0); - ## tsam = -1; else print_usage (); endif @@ -88,43 +86,25 @@ case 2 print_usage (); - case 3 # a, b, c without d ss (a, b, c) - d = zeros (rows (c), columns (b)); - tsam = 0; - - case 4 # continuous system ss (a, b, c, d), ss ([], [], [], d) - [b, c] = __gain_check__ (b, c, d); - tsam = 0; - - otherwise # default case - [b, c] = __gain_check__ (b, c, d); - argc = numel (varargin); - + otherwise # default case sys = ss (a, b, c, d, "prop1, "val1", ...) + argc = numel (varargin); # number of additional arguments after d if (issample (varargin{1}, 0)) # sys = ss (a, b, c, d, tsam, "prop1, "val1", ...) tsam = varargin{1}; argc--; if (argc > 0) varargin = varargin(2:end); endif - else # sys = ss (a, b, c, d, "prop1, "val1", ...) - tsam = 0; endif - endswitch - - if (isempty (a)) # static system - tsam = -1; - a = []; # avoid [](nx0) or [](0xn) - endif - + [a, b, c, d, tsam] = __adjust_ss_data__ (a, b, c, d, tsam); [p, m, n] = __ss_dim__ (a, b, c, d); stname = repmat ({""}, n, 1); ssdata = struct ("a", a, "b", b, "c", c, "d", d, - "e", e, + "e", [], "stname", {stname}); ltisys = lti (p, m, tsam); @@ -136,15 +116,3 @@ endif endfunction - - -function [b, c] = __gain_check__ (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); - endif - -endfunction \ No newline at end of file Added: trunk/octave-forge/main/control/inst/__adjust_ss_data__.m =================================================================== --- trunk/octave-forge/main/control/inst/__adjust_ss_data__.m (rev 0) +++ trunk/octave-forge/main/control/inst/__adjust_ss_data__.m 2010-10-16 21:35:46 UTC (rev 7850) @@ -0,0 +1,43 @@ +## 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 LTI Syncope. If not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## Common code for adjusting SS model data. +## Used by @ss/ss.m, others possibly follow. + +## Author: Lukas Reichlin <luk...@gm...> +## Created: October 2010 +## Version: 0.1 + +function [a, b, c, d, tsam] = __adjust_ss_data__ (a, b, c, d, tsam); + + if (isempty (a)) # static system + a = []; # avoid [](nx0) or [](0xn) + tsam = -1; + endif + + if (isempty (d)) # ss (a, b, c), ss (a, b, c, [], ...) + d = zeros (rows (c), columns (b)); + endif + + if (isempty (b) && isempty (c)) # sys = ss ([], [], [], d) + b = zeros (0, columns (d)); + c = zeros (rows(d), 0); + tsam = -1; + endif + +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. |