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