From: <par...@us...> - 2010-09-15 13:07:19
|
Revision: 7730 http://octave.svn.sourceforge.net/octave/?rev=7730&view=rev Author: paramaniac Date: 2010-09-15 13:07:07 +0000 (Wed, 15 Sep 2010) Log Message: ----------- control: have fun with cellfun Modified Paths: -------------- trunk/octave-forge/main/control/inst/ctrb.m trunk/octave-forge/main/control/inst/obsv.m Modified: trunk/octave-forge/main/control/inst/ctrb.m =================================================================== --- trunk/octave-forge/main/control/inst/ctrb.m 2010-09-15 11:20:24 UTC (rev 7729) +++ trunk/octave-forge/main/control/inst/ctrb.m 2010-09-15 13:07:07 UTC (rev 7730) @@ -1,5 +1,5 @@ -## Copyright (C) 1997, 2000, 2002, 2004, 2005, 2006, 2007 Kai P. Mueller -## Copyright (C) 2009 Lukas F. Reichlin +## Copyright (C) 2009 - 2010 Lukas F. Reichlin +## Copyright (C) 2009 Luca Favatella <sla...@gm...> ## ## This file is part of LTI Syncope. ## @@ -22,35 +22,32 @@ ## Controllability matrix. ## @end deftypefn -## Author: Kai P. Mueller <mu...@if...> -## Created: November 4, 1997 -## based on is_controllable.m of Scottedward Hodel +## Author: Lukas Reichlin <luk...@gm...> +## Created: October 2009 +## Version: 0.2 function co = ctrb (a, b) - if (nargin == 1) # ctrb (sys) + if (nargin == 1) # ctrb (sys) if (! isa (a, "lti")) error ("ctrb: argument must be an lti system"); endif [a, b] = ssdata (a); - elseif (nargin == 2) # ctrb (a, b) - if (! isnumeric (a) || ! isnumeric (b) || - rows (a) != rows (b) || ! issquare (a)) + elseif (nargin == 2) # ctrb (a, b) + if (! isreal (a) || ! isreal (b) + || rows (a) != rows (b) || ! issquare (a)) error ("ctrb: invalid arguments (a, b)"); endif else print_usage (); endif - [arows, acols] = size (a); - [brows, bcols] = size (b); + n = rows (a); # number of states + k = num2cell (0:n-1); # exponents for a - co = zeros (arows, acols*bcols); + tmp = cellfun (@(x) a^x*b, k, "uniformoutput", false); - for k = 1 : arows - co(:, ((k-1)*bcols + 1) : (k*bcols)) = b; - b = a * b; - endfor + co = horzcat (tmp{:}); endfunction Modified: trunk/octave-forge/main/control/inst/obsv.m =================================================================== --- trunk/octave-forge/main/control/inst/obsv.m 2010-09-15 11:20:24 UTC (rev 7729) +++ trunk/octave-forge/main/control/inst/obsv.m 2010-09-15 13:07:07 UTC (rev 7730) @@ -1,5 +1,4 @@ -## Copyright (C) 1997, 2000, 2002, 2004, 2005, 2006, 2007 Kai P. Mueller -## Copyright (C) 2009 Lukas F. Reichlin +## Copyright (C) 2009 - 2010 Lukas F. Reichlin ## Copyright (C) 2009 Luca Favatella <sla...@gm...> ## ## This file is part of LTI Syncope. @@ -23,27 +22,20 @@ ## Observability matrix. ## @end deftypefn -## Author: Kai P. Mueller <mu...@if...> -## Created: November 4, 1997 +## Author: Lukas Reichlin <luk...@gm...> +## Created: October 2009 +## Version: 0.2 function ob = obsv (a, c) - if (nargin == 1) # obsv (sys) - if (! isa (a, "lti")) - error ("obsv: argument must be an lti system"); - endif - [a, b, c] = ssdata (a); - elseif (nargin == 2) # obsv (a, c) - if (! isnumeric (a) || ! isnumeric (c) || - columns (a) != columns (c) || ! issquare (a)) - error ("obsv: invalid arguments (a, c)"); - endif + if (nargin == 1) # obsv (sys) + ob = ctrb (a.').'; # transpose is overloaded for lti models + elseif (nargin == 2) # obsv (a, c) + ob = ctrb (a.', c.').'; # size checked inside else print_usage (); endif - ob = ctrb (a.', c.').'; - endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |