From: <par...@us...> - 2012-06-29 06:08:38
|
Revision: 10702 http://octave.svn.sourceforge.net/octave/?rev=10702&view=rev Author: paramaniac Date: 2012-06-29 06:08:32 +0000 (Fri, 29 Jun 2012) Log Message: ----------- control-devel: work on draft code Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/arx.m trunk/octave-forge/extra/control-devel/src/Makefile Added Paths: ----------- trunk/octave-forge/extra/control-devel/src/is_matrix.cc Modified: trunk/octave-forge/extra/control-devel/inst/arx.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/arx.m 2012-06-29 06:07:27 UTC (rev 10701) +++ trunk/octave-forge/extra/control-devel/inst/arx.m 2012-06-29 06:08:32 UTC (rev 10702) @@ -16,8 +16,65 @@ ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{sys} =} arx (@var{dat}, @var{na}, @var{nb}) +## @deftypefn {Function File} {[@var{sys}, @var{x0}] =} arx (@var{dat}, @var{n}, @dots{}) +## @deftypefnx {Function File} {[@var{sys}, @var{x0}] =} arx (@var{dat}, @var{n}, @var{opt}, @dots{}) +## @deftypefnx {Function File} {[@var{sys}, @var{x0}] =} arx (@var{dat}, @var{opt}, @dots{}) +## @deftypefnx {Function File} {[@var{sys}, @var{x0}] =} arx (@var{dat}, @var{'na'}, @var{na}, @var{'nb'}, @var{nb}) ## ARX +## +## @strong{Inputs} +## @table @var +## @item dat +## iddata set containing the measurements. +## @item n +## The desired order of the resulting model @var{sys}. +## @item @dots{} +## Optional pairs of keys and values. @code{'key1', value1, 'key2', value2}. +## @item opt +## Optional struct with keys as field names. +## Struct @var{opt} can be created directly or +## by command @command{options}. @code{opt.key1 = value1, opt.key2 = value2}. +## @end table +## +## +## @strong{Outputs} +## @table @var +## @item sys +## Discrete-time transfer function model. +## If the second output argument @var{x0} is returned, +## @var{sys} becomes a state-space model. +## @item x0 +## Initial state vector. If @var{dat} is a multi-experiment dataset, +## @var{x0} becomes a cell vector containing an initial state vector +## for each experiment. +## @end table +## +## +## +## @strong{Option Keys and Values} +## @table @var +## @item 'na' +## The desired order of the resulting state-space system @var{sys}. +## @var{s} > @var{n} > 0. +## +## @item 'nb' +## The desired order of the resulting state-space system @var{sys}. +## @var{s} > @var{n} > 0. +## @end table +## +## +## @strong{Algorithm}@* +## Uses the formulae given in [1] on pages 318-319, +## 'Solving for the LS Estimate by QR Factorization'. +## For the initial conditions, SLICOT IB01CD is used by courtesy of +## @uref{http://www.slicot.org, NICONET e.V.} +## +## @strong{References}@* +## [1] Ljung, L. (1999) +## System Identification - Theory for the User +## Second Edition +## Prentice Hall, New Jersey. +## ## @end deftypefn ## Author: Lukas Reichlin <luk...@gm...> @@ -36,15 +93,14 @@ error ("arx: first argument must be an iddata dataset"); endif -% if (nargin > 2) # arx (dat, ...) - if (is_real_scalar (varargin{1})) # arx (dat, n, ...) - varargin = horzcat (varargin(2:end), {"na"}, varargin(1), {"nb"}, varargin(1)); - endif - if (isstruct (varargin{1})) # arx (dat, opt, ...), arx (dat, n, opt, ...) - varargin = horzcat (__opt2cell__ (varargin{1}), varargin(2:end)); - endif -% endif + if (is_real_scalar (varargin{1})) # arx (dat, n, ...) + varargin = horzcat (varargin(2:end), {"na"}, varargin(1), {"nb"}, varargin(1)); + endif + if (isstruct (varargin{1})) # arx (dat, opt, ...), arx (dat, n, opt, ...) + varargin = horzcat (__opt2cell__ (varargin{1}), varargin(2:end)); + endif + nkv = numel (varargin); # number of keys and values if (rem (nkv, 2)) Modified: trunk/octave-forge/extra/control-devel/src/Makefile =================================================================== --- trunk/octave-forge/extra/control-devel/src/Makefile 2012-06-29 06:07:27 UTC (rev 10701) +++ trunk/octave-forge/extra/control-devel/src/Makefile 2012-06-29 06:08:32 UTC (rev 10702) @@ -2,7 +2,8 @@ # BLAS_LIBS := $(shell mkoctfile -p BLAS_LIBS) FLIBS := $(shell mkoctfile -p FLIBS) -all: devel_slicot_functions.oct +all: devel_slicot_functions.oct \ + is_matrix.oct # unpack and compile SLICOT library slicotlibrary.a: slicot.tar.gz @@ -27,6 +28,10 @@ mkoctfile devel_slicot_functions.cc common.cc slicotlibrary.a lapacklibrary.a \ ${FLIBS} +# helpers +is_matrix.oct: is_matrix.cc + mkoctfile is_matrix.cc + clean: rm -rf *.o core octave-core *.oct *~ *.f slicot lapack-3.4.1 Added: trunk/octave-forge/extra/control-devel/src/is_matrix.cc =================================================================== --- trunk/octave-forge/extra/control-devel/src/is_matrix.cc (rev 0) +++ trunk/octave-forge/extra/control-devel/src/is_matrix.cc 2012-06-29 06:08:32 UTC (rev 10702) @@ -0,0 +1,60 @@ +/* + +Copyright (C) 2012 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/>. + +Return true if argument is a real matrix. + +Author: Lukas Reichlin <luk...@gm...> +Created: June 2012 +Version: 0.1 + +*/ + +#include <octave/oct.h> + +DEFUN_DLD (is_matrix, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {} is_matrix (@var{a}, @dots{})\n\ +Return true if argument is a matrix.\n\ +@var{[]} is a valid matrix.\n\ +Avoid nasty stuff like @code{true = isreal (\"a\")}\n\ +@seealso{is_real_matrix, is_real_square_matrix, is_real_vector, is_real_scalar}\n\ +@end deftypefn") +{ + octave_value retval = true; + int nargin = args.length (); + + if (nargin == 0) + { + print_usage (); + } + else + { + for (int i = 0; i < nargin; i++) + { + if (args(i).ndims () != 2 || ! args(i).is_numeric_type () + || ! (args(i).is_complex_type () || args(i).is_real_type ())) + { + retval = false; + break; + } + } + } + + return retval; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |