3381
|
1 ## Copyright (C) 1996 Auburn University. All Rights Reserved |
|
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, 59 Temple Place, Suite 330, Boston, MA 02111 USA. |
3346
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File } { outputs =} moddemo ( inputs ) |
|
21 ## @format |
|
22 ## Octave Controls toolbox demo: Model Manipulations demo |
|
23 ## Written by David Clem August 15, 1994 |
|
24 ## |
|
25 ## @end format |
|
26 ## @end deftypefn |
3213
|
27 |
|
28 function moddemo() |
3381
|
29 ## Written by David Clem August 15, 1994 |
|
30 ## a s hodel: updated to reflect updated output order in ss2zp |
3213
|
31 |
|
32 while (1) |
|
33 clc |
|
34 disp('Octave Model Manipulations Demo') |
|
35 disp('=======================================') |
|
36 disp(' 1) Perform continuous to discrete time conversion (c2d)') |
|
37 disp(' 2) Convert from state space to zero / pole form (ss2zp)') |
|
38 disp(' Convert from zero / pole to state space form (zp2ss)') |
|
39 disp(' 3) Convert from state space to transfer function form (ss2tf)') |
|
40 disp(' Convert from transfer function to state space form (tf2ss)') |
|
41 disp(' 4) Convert from transfer function to zero / pole form (tf2zp)') |
|
42 disp(' Convert from zero / pole to transfer function form (zp2tf)') |
|
43 disp(' 5) Return to main demo menu') |
|
44 disp(' ') |
|
45 k=6; |
|
46 while(k > 5 || k < 1) |
|
47 k = input('Please enter a number:'); |
|
48 endwhile |
|
49 if (k == 1) |
|
50 clc |
|
51 disp('Perform continuous to discrete time conversion (c2d)\n') |
|
52 disp('Example #1, Consider the following continuous time state space system:\n') |
|
53 a=[0 1;-25 -4] |
|
54 b=[0;1] |
|
55 c=[1 1] |
|
56 d=1 |
|
57 prompt |
|
58 disp('\nTo convert this to a discrete time system (using a zero order hold),') |
|
59 disp('use the following commands:\n') |
|
60 cmd="sys=ss2sys(a,b,c,d);"; |
|
61 run_cmd |
|
62 cmd="dsys = c2d(sys,0.2);"; |
|
63 run_cmd |
|
64 cmd="sysout(dsys);"; |
|
65 run_cmd |
|
66 disp('Function check\n') |
|
67 disp('Check the poles of sys vs dsys:\n') |
|
68 cmd="[da,db]=sys2ss(dsys);"; |
|
69 run_cmd |
|
70 cmd="lam = eig(a);"; |
|
71 run_cmd |
|
72 disp('Discretize the continuous time eigenvalues using the matrix exponential:\n') |
|
73 disp('lambc = exp(lam*0.2)\n') |
|
74 lambc = exp(lam*0.2) |
|
75 disp('Check the eigenvalues of da\n') |
|
76 lambd = eig(da) |
|
77 disp('Calculate the difference between lambd and lambc:\n') |
|
78 cmd = 'error = sort(lambd)-sort(lambc)\n'; |
|
79 run_cmd |
|
80 disp("The error is on the order of roundoff noise, so we're o.k.") |
|
81 prompt |
|
82 clc |
|
83 elseif (k == 2) |
|
84 clc |
|
85 disp('Convert from state space to zero / pole form (ss2zp)\n') |
|
86 disp('Example #1, Consider the following state space system:\n') |
|
87 a=[0 3 1;-2 -4 5;5 8 2] |
|
88 b=[0;5;2.5] |
|
89 c=[6 -1.9 2] |
|
90 d=[-20] |
|
91 prompt |
|
92 disp(' ') |
|
93 disp('\nTo find the poles and zeros of this sytstem, use the following command:\n') |
|
94 disp('\n[zer, pol] = ss2zp(a, b, c, d)\n') |
|
95 prompt |
|
96 disp('Results:\n') |
|
97 [zer, pol] = ss2zp(a, b, c, d) |
|
98 disp('Variable Description:\n') |
|
99 disp('zer, pol => zeros and poles of the state space system') |
|
100 disp('a, b, c, d => state space system\n') |
|
101 prompt |
|
102 clc |
|
103 disp('Convert from zero / pole to state space form (zp2ss)\n') |
|
104 disp('Example #1, Consider the following set of zeros and poles:\n') |
|
105 zer |
|
106 pol |
|
107 prompt |
|
108 disp('\nTo find an equivalent state space representation for this set of poles') |
|
109 disp('and zeros, use the following commands:\n') |
|
110 k=1 |
|
111 disp('\n[na, nb, nc, nd] = zp2ss(zer, pol, k)\n') |
|
112 prompt |
|
113 disp('Results:\n') |
|
114 [na, nb, nc, nd] = zp2ss(zer, pol, k) |
|
115 disp('Variable Description:\n') |
|
116 disp('na, nb, nc, nd => state space system equivalent to zero / pole input') |
|
117 disp('zer, pol => zeros and poles of desired state space system') |
|
118 disp('k => gain associated with the zeros\n') |
|
119 prompt |
|
120 disp('Function check\n') |
|
121 disp('Are the eigenvalues of the origonal state space system the same as the') |
|
122 disp('eigenvalues of the newly constructed state space system ?\n') |
|
123 disp('Find the difference between the two sets of eigenvalues') |
|
124 disp('error = sort(eig(a)) - sort(eig(na))\n') |
|
125 error = sort(eig(a)) - sort(eig(na)) |
|
126 prompt |
|
127 clc |
|
128 elseif (k == 3) |
|
129 clc |
|
130 disp('Convert from state space to transfer function (ss2tf)\n') |
|
131 disp('Example #1, Consider the following state space system:\n') |
|
132 a=[0 1;-2 -3] |
|
133 b=[1;1] |
|
134 c=[1 9] |
|
135 d=[1] |
|
136 prompt |
|
137 disp('\nTo find an equivalent transfer function for this system, use') |
|
138 disp('the following command:\n') |
|
139 disp('[num, den] = ss2tf(a, b, c, d)\n') |
|
140 prompt |
|
141 disp('Results:\n') |
|
142 [num,den] = ss2tf(a, b, c, d) |
|
143 disp('Variable Description:\n') |
|
144 disp('num, den => numerator and denominator of transfer function that is') |
|
145 disp(' equivalent to the state space system') |
|
146 disp('a, b, c, d => state space system\n') |
|
147 prompt |
|
148 clc |
|
149 disp('Convert from transfer function to state space form (tf2ss)\n') |
|
150 disp('Example #1, Consider the following transfer function:\n') |
|
151 num |
|
152 den |
|
153 prompt |
|
154 disp('\nTo find an equivalent state space representation for this system, use') |
|
155 disp('the following command:\n') |
|
156 disp('[a, b, c, d] = tf2ss(num, den)\n') |
|
157 prompt |
|
158 disp('Results:\n') |
|
159 [a, b, c, d] = tf2ss(num, den) |
|
160 disp('Variable Description:\n') |
|
161 disp('a, b, c, d => state space system equivalent to transfer function input') |
|
162 disp('num, den => numerator and denominator of transfer function that is equivalent') |
|
163 disp(' to the state space system\n') |
|
164 prompt |
|
165 clc |
|
166 elseif (k == 4) |
|
167 clc |
|
168 disp('Convert from transfer function to zero / pole form (tf2zp)\n') |
|
169 disp('Example #1, Consider the following transfer function:\n') |
|
170 num=[1 2 3 4 5 ] |
|
171 den=[1 2 3 4 5 6 7] |
|
172 prompt |
|
173 disp('\nTo find the zeros and poles of this system, use the following command:\n') |
|
174 disp('[zer,pol] = tf2zp(num,den)\n') |
|
175 prompt |
|
176 disp('Results:\n') |
|
177 [zer,pol] = tf2zp(num,den) |
|
178 disp('Variable Description:\n') |
|
179 disp('zer,pol => zeros and poles of the transfer function') |
|
180 disp('num, den => numerator and denominator of transfer function\n') |
|
181 prompt |
|
182 clc |
|
183 disp('Convert from zero / pole to transfer function (zp2tf)\n') |
|
184 disp('Example #1, Consider the following set of zeros and poles:\n') |
|
185 zer |
|
186 pol |
|
187 prompt |
|
188 disp('\nTo find an equivalent transfer function representation for this set') |
|
189 disp('of poles and zeros, use the following commands:\n') |
|
190 k=1 |
|
191 disp('\n[num, den] = zp2tf(zer, pol, k)\n') |
|
192 prompt |
|
193 disp('Results:\n') |
|
194 [num, den] = zp2tf(zer, pol, k) |
|
195 disp('Variable Description:\n') |
|
196 disp('[num, den] => transfer function representation of desired set of zeros') |
|
197 disp(' and poles') |
|
198 disp('a, b, c, d => state space system') |
|
199 disp('zer, pol => zeros and poles of desired state space system') |
|
200 disp('k => gain associated with the zeros\n') |
|
201 prompt |
|
202 clc |
|
203 elseif (k == 5) |
|
204 return |
|
205 endif |
|
206 endwhile |
|
207 endfunction |