From: <par...@us...> - 2011-12-01 20:25:24
|
Revision: 9239 http://octave.svn.sourceforge.net/octave/?rev=9239&view=rev Author: paramaniac Date: 2011-12-01 20:25:17 +0000 (Thu, 01 Dec 2011) Log Message: ----------- control-devel: add first controller reduction code, doc fixes Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/btamodred.m trunk/octave-forge/extra/control-devel/inst/spamodred.m Added Paths: ----------- trunk/octave-forge/extra/control-devel/inst/__conred_sb16ad__.m trunk/octave-forge/extra/control-devel/inst/btaconred.m trunk/octave-forge/extra/control-devel/inst/spaconred.m Added: trunk/octave-forge/extra/control-devel/inst/__conred_sb16ad__.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/__conred_sb16ad__.m (rev 0) +++ trunk/octave-forge/extra/control-devel/inst/__conred_sb16ad__.m 2011-12-01 20:25:17 UTC (rev 9239) @@ -0,0 +1,173 @@ +## Copyright (C) 2011 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 -*- +## @deftypefn{Function File} {[@var{sysr}, @var{info}] =} __conred_sb16ad__ (@var{method}, @dots{}) +## Backend for btaconred and spaconred. +## @end deftypefn + +## Author: Lukas Reichlin <luk...@gm...> +## Created: December 2011 +## Version: 0.1 + +function [sysr, info] = __conred_sb16ad__ (method, varargin) + + if (nargin < 3) + print_usage (); + endif + + if (method != "bta" && method != "spa") + error ("modred: invalid method"); + endif + + G = varargin{1}; + K = varargin{2}; + varargin = varargin(3:end); + + if (! isa (G, "lti")) + error ("%sconred: first argument must be an LTI system", method); + endif + + if (! isa (K, "lti")) + error ("%sconred: second argument must be an LTI system", method); + endif + + if (nargin > 3) # *conred (G, K, ...) + if (is_real_scalar (varargin{1})) # *conred (G, K, nr) + varargin = horzcat (varargin(2:end), {"order"}, varargin(1)); + endif + if (isstruct (varargin{1})) # *conred (G, K, opt, ...), *conred (G, K, nr, opt, ...) + varargin = horzcat (__opt2cell__ (varargin{1}), varargin(2:end)); + endif + ## order placed at the end such that nr from *conred (G, K, nr, ...) + ## and *conred (G, K, nr, opt, ...) overrides possible nr's from + ## key/value-pairs and inside opt struct (later keys override former keys, + ## nr > key/value > opt) + endif + + npv = numel (varargin); # number of properties and values + + if (rem (npv, 2)) + error ("%sconred: properties and values must come in pairs", method); + endif + + [a, b, c, d, tsam, scaled] = ssdata (G); + [ac, bc, cc, dc, tsamc, scaledc] = ssdata (K); + [p, m] = size (G); + [pc, mc] = size (K); + dt = isdt (G); + + ## default arguments + alpha = __modred_default_alpha__ (dt); + av = bv = cv = dv = []; + jobv = 0; + aw = bw = cw = dw = []; + jobw = 0; + alphac = alphao = 0.0; + tol1 = 0.0; + tol2 = 0.0; + dico = 0; + jobc = jobo = 0; + bf = true; # balancing-free + weight = 1; + equil = 0; + ordsel = 1; + nr = 0; + + ## handle properties and values + for k = 1 : 2 : npv + prop = lower (varargin{k}); + val = varargin{k+1}; + switch (prop) + case {"left", "v"} + [av, bv, cv, dv, jobv] = __modred_check_weight__ (val, dt, p, []); + + case {"right", "w"} + [aw, bw, cw, dw, jobw] = __modred_check_weight__ (val, dt, [], m); + + case {"order", "n", "nr"} + [nr, ordsel] = __modred_check_order__ (val); + + case "tol1" + tol1 = __modred_check_tol__ (val, "tol1"); + + case "tol2" + tol2 = __modred_check_tol__ (val, "tol2"); + + case "alpha" + alpha = __modred_check_alpha__ (val, dt); + + case "approach" + switch (tolower (val)) + case "sr" + bf = false; + case "bfsr" + bf = true; + otherwise + error ("modred: ""%s"" is an invalid approach", val); + endswitch + + ## TODO: alphac, alphao, jobc, jobo + + otherwise + warning ("modred: invalid property name ""%s"" ignored", prop); + endswitch + endfor + + ## handle type of frequency weighting + if (jobv && jobw) + weight = 3; # 'B': both left and right weightings V and W are used + elseif (jobv) + weight = 1; # 'L': only left weighting V is used (W = I) + elseif (jobw) + weight = 2; # 'R': only right weighting W is used (V = I) + else + weight = 0; # 'N': no weightings are used (V = I, W = I) + endif + + ## handle model reduction approach + if (method == "bta" && ! bf) # 'B': use the square-root Balance & Truncate method + job = 0; + elseif (method == "bta" && bf) # 'F': use the balancing-free square-root Balance & Truncate method + job = 1; + elseif (method == "spa" && ! bf) # 'S': use the square-root Singular Perturbation Approximation method + job = 2; + elseif (method == "spa" && bf) # 'P': use the balancing-free square-root Singular Perturbation Approximation method + job = 3; + else + error ("modred: invalid job option"); # this should never happen + endif + + + ## perform model order reduction + [ar, br, cr, dr, nr, hsv, ns] = slab09id (a, b, c, d, dico, equil, nr, ordsel, alpha, job, \ + av, bv, cv, dv, \ + aw, bw, cw, dw, \ + weight, jobc, jobo, alphac, alphao, \ + tol1, tol2); + + ## assemble reduced order model + sysr = ss (ar, br, cr, dr, tsam); + + ## assemble info struct + info = struct ("nr", nr, "ns", ns, "hsv", hsv); + +endfunction + + + + Added: trunk/octave-forge/extra/control-devel/inst/btaconred.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/btaconred.m (rev 0) +++ trunk/octave-forge/extra/control-devel/inst/btaconred.m 2011-12-01 20:25:17 UTC (rev 9239) @@ -0,0 +1,104 @@ +## Copyright (C) 2011 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 -*- +## @deftypefn{Function File} {[@var{Kr}, @var{info}] =} btaconred (@var{G}, @var{K}, @dots{}) +## @deftypefnx{Function File} {[@var{Kr}, @var{info}] =} btaconred (@var{G}, @var{K}, @var{nr}, @dots{}) +## @deftypefnx{Function File} {[@var{Kr}, @var{info}] =} btaconred (@var{G}, @var{K}, @var{opt}, @dots{}) +## @deftypefnx{Function File} {[@var{Kr}, @var{info}] =} btaconred (@var{G}, @var{K}, @var{nr}, @var{opt}, @dots{}) +## +## Model order reduction by frequency weighted optimal Hankel-norm approximation method. +## +## @strong{Inputs} +## @table @var +## @item sys +## LTI model to be reduced. +## @item @dots{} +## Pairs of properties and values. +## TODO: describe options. +## @end table +## +## @strong{Outputs} +## @table @var +## @item sysr +## Reduced order state-space model. +## @item nr +## The order of the obtained system @var{sysr}. +## @end table +## +## @strong{Algorithm}@* +## Uses SLICOT SB16AD by courtesy of +## @uref{http://www.slicot.org, NICONET e.V.} +## @end deftypefn + +## Author: Lukas Reichlin <luk...@gm...> +## Created: December 2011 +## Version: 0.1 + +function [Kr, info] = btaconred (varargin) + + [Kr, info] = __conred_sb16ad__ ("bta", varargin{:}); + +endfunction + + +%!shared Mo, Me +%! A = [ -1. 0. 4. +%! 0. 2. 0. +%! 0. 0. -3. ]; +%! +%! B = [ 1. +%! 1. +%! 1. ]; +%! +%! C = [ 1. 1. 1. ]; +%! +%! D = [ 0. ]; +%! +%! G = ss (A, B, C, D, "scaled", true); +%! +%! AC = [ -26.4000, 6.4023, 4.3868; +%! 32.0000, 0, 0; +%! 0, 8.0000, 0 ]; +%! +%! BC = [ -16 +%! 0 +%! 0 ]; +%! +%! CC = [ 9.2994 1.1624 0.1090 ]; +%! +%! DC = [ 0 ]; +%! +%! K = ss (AV, BV, CV, DV, "scaled", true); +%! +%! Kr = btaconred (G, K, 2, "weight", "ERROR", "tol1", 0.1, "tol2", 0.0); +%! [Ao, Bo, Co, Do] = ssdata (Kr); +%! +%! Ae = [ 9.1900 0.0000 +%! 0.0000 -34.5297 ]; +%! +%! Be = [ -11.9593 +%! 86.3137 ]; +%! +%! Ce = [ 2.8955 -1.3566 ]; +%! +%! De = [ 0.0000 ]; +%! +%! Mo = [Ao, Bo; Co, Do]; +%! Me = [Ae, Be; Ce, De]; +%! +%!assert (Mo, Me, 1e-4); \ No newline at end of file Modified: trunk/octave-forge/extra/control-devel/inst/btamodred.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/btamodred.m 2011-12-01 19:56:49 UTC (rev 9238) +++ trunk/octave-forge/extra/control-devel/inst/btamodred.m 2011-12-01 20:25:17 UTC (rev 9239) @@ -16,10 +16,10 @@ ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn{Function File} {[@var{Gr}, @var{nr}] =} btamodred (@var{G}, @dots{}) -## @deftypefnx{Function File} {[@var{Gr}, @var{nr}] =} btamodred (@var{G}, @var{nr}, @dots{}) -## @deftypefnx{Function File} {[@var{Gr}, @var{nr}] =} btamodred (@var{G}, @var{opt}, @dots{}) -## @deftypefnx{Function File} {[@var{Gr}, @var{nr}] =} btamodred (@var{G}, @var{nr}, @var{opt}, @dots{}) +## @deftypefn{Function File} {[@var{Gr}, @var{info}] =} btamodred (@var{G}, @dots{}) +## @deftypefnx{Function File} {[@var{Gr}, @var{info}] =} btamodred (@var{G}, @var{nr}, @dots{}) +## @deftypefnx{Function File} {[@var{Gr}, @var{info}] =} btamodred (@var{G}, @var{opt}, @dots{}) +## @deftypefnx{Function File} {[@var{Gr}, @var{info}] =} btamodred (@var{G}, @var{nr}, @var{opt}, @dots{}) ## ## Model order reduction by frequency weighted optimal Hankel-norm approximation method. ## Added: trunk/octave-forge/extra/control-devel/inst/spaconred.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/spaconred.m (rev 0) +++ trunk/octave-forge/extra/control-devel/inst/spaconred.m 2011-12-01 20:25:17 UTC (rev 9239) @@ -0,0 +1,58 @@ +## Copyright (C) 2011 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 -*- +## @deftypefn{Function File} {[@var{Kr}, @var{info}] =} spaconred (@var{G}, @var{K}, @dots{}) +## @deftypefnx{Function File} {[@var{Kr}, @var{info}] =} spaconred (@var{G}, @var{K}, @var{nr}, @dots{}) +## @deftypefnx{Function File} {[@var{Kr}, @var{info}] =} spaconred (@var{G}, @var{K}, @var{opt}, @dots{}) +## @deftypefnx{Function File} {[@var{Kr}, @var{info}] =} spaconred (@var{G}, @var{K}, @var{nr}, @var{opt}, @dots{}) +## +## Model order reduction by frequency weighted optimal Hankel-norm approximation method. +## +## @strong{Inputs} +## @table @var +## @item sys +## LTI model to be reduced. +## @item @dots{} +## Pairs of properties and values. +## TODO: describe options. +## @end table +## +## @strong{Outputs} +## @table @var +## @item sysr +## Reduced order state-space model. +## @item nr +## The order of the obtained system @var{sysr}. +## @end table +## +## @strong{Algorithm}@* +## Uses SLICOT SB16AD by courtesy of +## @uref{http://www.slicot.org, NICONET e.V.} +## @end deftypefn + +## Author: Lukas Reichlin <luk...@gm...> +## Created: December 2011 +## Version: 0.1 + +function [Kr, info] = spaconred (varargin) + + [Kr, info] = __conred_sb16ad__ ("spa", varargin{:}); + +endfunction + +## TODO: add a test \ No newline at end of file Modified: trunk/octave-forge/extra/control-devel/inst/spamodred.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/spamodred.m 2011-12-01 19:56:49 UTC (rev 9238) +++ trunk/octave-forge/extra/control-devel/inst/spamodred.m 2011-12-01 20:25:17 UTC (rev 9239) @@ -16,10 +16,10 @@ ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn{Function File} {[@var{Gr}, @var{nr}] =} spamodred (@var{G}, @dots{}) -## @deftypefnx{Function File} {[@var{Gr}, @var{nr}] =} spamodred (@var{G}, @var{nr}, @dots{}) -## @deftypefnx{Function File} {[@var{Gr}, @var{nr}] =} spamodred (@var{G}, @var{opt}, @dots{}) -## @deftypefnx{Function File} {[@var{Gr}, @var{nr}] =} spamodred (@var{G}, @var{nr}, @var{opt}, @dots{}) +## @deftypefn{Function File} {[@var{Gr}, @var{info}] =} spamodred (@var{G}, @dots{}) +## @deftypefnx{Function File} {[@var{Gr}, @var{info}] =} spamodred (@var{G}, @var{nr}, @dots{}) +## @deftypefnx{Function File} {[@var{Gr}, @var{info}] =} spamodred (@var{G}, @var{opt}, @dots{}) +## @deftypefnx{Function File} {[@var{Gr}, @var{info}] =} spamodred (@var{G}, @var{nr}, @var{opt}, @dots{}) ## ## Model order reduction by frequency weighted optimal Hankel-norm approximation method. ## This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |