home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / ltifr.m < prev    next >
Text File  |  1999-03-05  |  2KB  |  86 lines

  1. # Copyright (C) 1996 A. Scottedward Hodel 
  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 the 
  7. # Free Software Foundation; either version 2, or (at your option) any 
  8. # later version. 
  9. # Octave is distributed in the hope that it will be useful, but WITHOUT 
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  11. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  12. # for more details.
  13. # You should have received a copy of the GNU General Public License 
  14. # along with Octave; see the file COPYING.  If not, write to the Free 
  15. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  16.  
  17. function out = ltifr(a,b,w)
  18.   #ltifr:  Linear time invarient frequency response of SISO systems
  19.   # out = ltifr(A,B,w)
  20.   # user enters the A and B matrices
  21.   #
  22.   # out = ltifr(sys,w)
  23.   # user enters the system, SYS
  24.   #
  25.   # this function takes the system matrices, A and B and
  26.   # returns:               -1
  27.   #          G(s) = (jw I-A) B
  28.   #
  29.   # for complex frequencies s = jw. 
  30.  
  31.   # R. B. Tenison, D. Clem, A. S. Hodel, July 1995
  32.   # updated by John Ingram August 1996 for system format
  33.   
  34.   if ((nargin < 2) || (nargin > 3))
  35.     error("incorrect number of input arguments");
  36.   endif
  37.  
  38.   if (nargin == 2)
  39.     sys = a;
  40.     w = b;
  41.     if(!is_struct(sys))
  42.       error("two arguments: 1st must be a system data structure");
  43.     endif
  44.  
  45.     if (!is_vector(w))
  46.       error("w must be a vector");
  47.     endif
  48.     
  49.     [nn,nz,mm,pp] = sysdimensions(sys);
  50.     if(mm != 1)       error("sys has %d > 1 inputs",mm); endif
  51.  
  52.     [a,b] = sys2ss(sys);
  53.  
  54.   else  
  55.  
  56.     if (columns(a) != rows(b)),
  57.       error("ltifr:  A(%dx%d), B(%dx%d) not compatibly dimensioned", ...
  58.     rows(a), columns(a), rows(b), columns(b));
  59.     endif
  60.  
  61.     if(columns(b) != 1)
  62.       error("ltifr: b(%dx%d) must be a single column vector", ...
  63.     rows(b),columns(b));
  64.     endif
  65.   
  66.     if (!is_square(a))
  67.       error("ltifr:  A(%dx$d) must be square.",rows(a),columns(a))
  68.     endif
  69.  
  70.   endif
  71.  
  72.   if (!is_vector(w))
  73.     error("w must be a vector");
  74.   endif
  75.  
  76.   ey = eye(size(a));
  77.   lw = length(w);
  78.   out = ones(columns(a),lw);
  79.  
  80.   for ii=1:lw,
  81.     out(:,ii) = (w(ii)*ey-a)\b;
  82.   endfor
  83. endfunction
  84.