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

  1. # Copyright (C) 1993, 1994, 1995 John W. Eaton
  2. # This file is part of Octave.
  3. # Octave is free software; you can redistribute it and/or modify it
  4. # under the terms of the GNU General Public License as published by the
  5. # Free Software Foundation; either version 2, or (at your option) any
  6. # later version.
  7. # Octave is distributed in the hope that it will be useful, but WITHOUT
  8. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  10. # for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with Octave; see the file COPYING.  If not, write to the Free
  13. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  14.  
  15. function damp(p, tsam)
  16. # Usage: damp(p[, tsam])
  17. #      Displays eigenvalues, natural frequencies and damping ratios
  18. #      of the eigenvalues of a matrix p or the A-matrix of a
  19. #      system p, respectively.
  20. #      If p is a system, tsam must not be specified.
  21. #      If p is a matrix and tsam is specified, eigenvalues
  22. #      of p are assumed to be in z-domain.
  23. #
  24. # See also: eig
  25.  
  26. # Written by Kai P. Mueller September 29, 1997.
  27. # Update
  28.  
  29.   # assume a continuous system
  30.   DIGITAL = 0;
  31.   if(nargin < 1 || nargin > 2)
  32.     usage("damp(p,[ tsamp])")
  33.   endif
  34.   if(is_struct(p))
  35.     if (nargin != 1)
  36.       error("damp: when p is a system, tsamp parameter is not allowed.");
  37.     endif
  38.     [aa, b, c, d, t_samp] = sys2ss(p);
  39.     DIGITAL = is_digital(p);
  40.   else
  41.     aa = p;
  42.     if (nargin == 2)
  43.         DIGITAL = 1;
  44.         t_samp = tsam;
  45.     endif
  46.   endif
  47.   if (!is_square(aa))
  48.     error("damp: Matrix p is not square.")
  49.   endif
  50.   if (DIGITAL && t_samp <= 0.0)
  51.     error("damp: Sampling time tsam must not be <= 0.")
  52.   endif
  53.  
  54.   # all checks done.
  55.   e = eig(aa);
  56.   [n, m] = size(aa);
  57.   if (DIGITAL)
  58.     printf("  (discrete system with sampling time %f)\n", t_samp);
  59.   endif
  60.   printf("............... Eigenvalue ...........     Damping     Frequency\n");
  61.   printf("--------[re]---------[im]--------[abs]----------------------[Hz]\n");
  62.   for i = 1:n
  63.     pole = e(i);
  64.     cpole = pole;
  65.     if (DIGITAL)
  66.       cpole = log(pole) / t_samp;
  67.     endif
  68.     d0 = -cos(atan2(imag(cpole), real(cpole)));
  69.     f0 = 0.5 / pi * abs(cpole);
  70.     if (abs(imag(cpole)) < eps)
  71.       printf("%12f         ---  %12f  %10f  %12f\n",
  72.              real(pole), abs(pole), d0, f0);
  73.     else
  74.       printf("%12f %12f %12f  %10f  %12f\n",
  75.              real(pole), imag(pole), abs(pole), d0, f0);
  76.     endif
  77.   endfor
  78.  
  79. endfunction
  80.