home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / control / dare.m < prev    next >
Text File  |  1999-04-29  |  3KB  |  97 lines

  1. ## Copyright (C) 1996, 1997 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## Usage: x = dare (a, b, c, r {,opt})
  21. ##
  22. ## Solves discrete-time algebraic riccati equation
  23. ##
  24. ##   a' x a - x + a' x b (r + b' x b)^{-1} b' x a + c = 0
  25. ##
  26. ## for
  27. ##
  28. ##   a: nxn
  29. ##   b: nxm
  30. ##   c: nxn, symmetric positive semidefinite
  31. ##   r: mxm, invertible
  32. ##
  33. ## If c is not square, then the function attempts to use c'*c instead.
  34. ##
  35. ## Solution method: Generalized eigenvalue approach (Van Dooren; SIAM J.
  36. ## Sci. Stat. Comput., Vol 2) applied  to the appropriate symplectic pencil.
  37. ##
  38. ## See also: Ran and Rodman, "Stable Hermitian Solutions of Discrete
  39. ## Algebraic Riccati Equations," Mathematics of Control, Signals and
  40. ## Systems, Vol 5, no 2 (1992)  pp 165-194.
  41. ##
  42. ## opt is an option passed to the eigenvalue balancing routine default
  43. ## is "B".
  44. ##
  45. ## See also: balance, are
  46.  
  47. ## Author: A. S. Hodel <scotte@eng.auburn.edu>
  48. ## Created: August 1993
  49. ## Adapted-By: jwe
  50.  
  51. function x = dare (a, b, c, r, opt)
  52.  
  53.   if (nargin == 4 | nargin == 5)
  54.     if (nargin == 5)
  55.       if (opt != "N" || opt != "P" || opt != "S" || opt != "B")
  56.     warning ("dare: opt has an invalid value -- setting to B");
  57.     opt = "B";
  58.       endif
  59.     else
  60.       opt = "B";
  61.     endif
  62.  
  63.     # dimension checks are done in is_contr, is_obsrv
  64.     if (is_contr (a, b) == 0)
  65.       warning ("dare: a,b are not controllable");
  66.     elseif (is_obsrv (a, c) == 0)
  67.       warning ("dare: a,c are not observable");
  68.     endif
  69.  
  70.     if ((p = is_sqr (c)) == 0)
  71.       c = c'*c;
  72.       p = rows (c);
  73.     endif
  74.  
  75.     ## Check r dimensions.
  76.     n = rows(a);
  77.     m = columns(b);
  78.     if ((m1 = is_sqr (r)) == 0)
  79.       warning ("dare: r is not square");
  80.     elseif (m1 != m)
  81.       warning ("b,r are not conformable");
  82.     endif
  83.  
  84.     s1 = [a, zeros(n) ; -c, eye(n)];
  85.     s2 = [eye(n), (b/r)*b' ; zeros(n), a'];
  86.     [c,d,s1,s2] = balance(s1,s2,opt);
  87.     [aa,bb,u,lam] = qz(s1,s2,"S");
  88.     u = d*u;
  89.     n1 = n+1;
  90.     n2 = 2*n;
  91.     x = u (n1:n2, 1:n)/u(1:n, 1:n);
  92.   else
  93.     usage ("x = dare (a, b, c, r {,opt})");
  94.   endif
  95.  
  96. endfunction
  97.