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