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