annotate scripts/control/base/analdemo.m @ 7016:93c65f2a5668

[project @ 2007-10-12 06:40:56 by jwe]
author jwe
date Fri, 12 Oct 2007 06:41:26 +0000
parents 4c8a2e4e0717
children a1dbe9d80eee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 1996 Auburn University. All rights reserved.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
2 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
4 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
6 ## under the terms of the GNU General Public License as published by
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
8 ## your option) any later version.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
9 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
13 ## General Public License for more details.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
14 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
17 ## <http://www.gnu.org/licenses/>.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
18
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
20 ## @deftypefn {Function File} {} analdemo ()
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
21 ## Octave Controls toolbox demo: State Space analysis demo
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
22 ## @end deftypefn
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
23
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
24 ## Author: David Clem
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
25 ## Created: August 15, 1994
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
26 ## Updated by John Ingram December 1996
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
27
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
28 function analdemo ()
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
29
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
30 while (1)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
31 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
32 k=0;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
33 while(k > 8 || k < 1)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
34 k = menu("Octave State Space Analysis Demo", ...
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
35 "System gramians (gram, dgram)", ...
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
36 "System zeros (tzero)", ...
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
37 "Continuous => Discrete and Discrete => Continuous conversions (c2d,d2c)", ...
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
38 "Algebraic Riccati Equation (are, dare)", ...
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
39 "Balanced realizations (balreal, dbalreal)", ...
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
40 "Open loop truncations via Hankel singular values (balreal, dbalreal)", ...
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
41 "SISO pole placement", ...
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
42 "Return to main demo menu");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
43 endwhile
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
44 if (k == 1)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
45 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
46 help dgram
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
47 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
48
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
49 clc
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
50 disp("System Gramians: (see Moore, IEEE T-AC, 1981) \n");
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
51 disp("Example #1, consider the discrete time state space system:\n");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
52 a=[1, 5, -8.4; 1.2, -3, 5; 1, 7, 9]
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
53 b=[1, 5; 2, 6; -4.4, 5]
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
54 c=[1, -1.5, 2; 6, -9.8, 1]
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
55 d=0
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
56 prompt
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
57 disp("\nThe discrete controllability gramian is computed as follows:");
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
58 cmd = "gramian = dgram(a, b);";
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
59 run_cmd;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
60 disp("Results:\n");
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
61 gramian = dgram(a,b)
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
62 disp("Variable Description:\n");
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
63 disp("gramian => discrete controllability gramian");
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
64 disp("a, b => a and b matrices of discrete time system\n");
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
65 disp("A dual approach may be used to compute the observability gramian.");
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
66 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
67 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
68
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
69 help gram
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
70 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
71 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
72
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
73 disp("Example #2, consider the continuous state space system:\n");
4139
02ca908056e9 [project @ 2002-11-01 00:49:13 by jwe]
jwe
parents: 3431
diff changeset
74 a=[1, 3, -10.2; 3.7, -2, 9; 1, 3, 7]
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
75 b=[1, 12; 6, 2; -3.8, 7]
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
76 c=[1, -1.1, 7; 3, -9.8, 2]
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
77 d=0
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
78 prompt
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
79 disp("\nThe continuous controllability gramian is computed as follows:");
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
80 cmd = "gramian = gram(a, b);";
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
81 run_cmd;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
82 disp("Results:\n");
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
83 gramian = gram(a,b)
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
84 disp("Variable Description:\n");
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
85 disp("gramian => continuous controllability gramian");
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
86 disp("a, b => a and b matrices of continuous time system\n");
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
87 disp("A dual approach may be used to compute the observability gramian.");
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
88 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
89 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
90
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
91
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
92 elseif (k == 2)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
93 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
94 help tzero
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
95 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
96
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
97 disp("System zeros (tzero) example\n");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
98 disp("Example #1, consider the state space system:\n");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
99 a=[0, 1, 0; -10, -2, 0; -10, 0, -8]
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
100 b=[0; 1; 9]
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
101 c=[-10, 0, -4]
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
102 d=1
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
103 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
104 disp("\nTo compute the zeros of this system, enter the following command:\n");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
105 cmd = "zer = tzero(a,b,c,d);";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
106 run_cmd;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
107 disp("Results:\n");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
108 zer = tzero(a,b,c,d)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
109 disp("Variable Description:\n");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
110 disp("zer => zeros of state space system");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
111 disp("a, b, c, d => state space system used as input argument");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
112 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
113 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
114
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
115 disp("Example #2, consider the state space system from example 1 again:");
4771
b8105302cfe8 [project @ 2004-02-16 17:45:50 by jwe]
jwe
parents: 4139
diff changeset
116 cmd = "sys = ss(a,b,c,d);";
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
117 disp(cmd);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
118 eval(cmd);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
119 sysout(sys);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
120 disp("\nThe zeros of this system can also be calculated directly from the");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
121 disp("system variable:");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
122 cmd = "zer = tzero(sys);";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
123 run_cmd;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
124 disp("Results:\n")
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
125 zer = tzero(sys)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
126 disp("Variable Description:\n");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
127 disp("zer => zeros of state space system");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
128 disp("sys => state space system used as input argument");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
129 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
130 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
131
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
132 elseif (k == 3)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
133 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
134 help c2d
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
135 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
136
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
137 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
138 disp("Continuous => Discrete and Discrete => Continuous conversions (c2d,d2c)");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
139 disp("\nExample #1, consider the following continuous state space system");
4771
b8105302cfe8 [project @ 2004-02-16 17:45:50 by jwe]
jwe
parents: 4139
diff changeset
140 cmd = "sys_cont = ss([-11, 6; -15, 8], [1; 2], [2, -1], 0);";
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
141 eval(cmd);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
142 disp(cmd);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
143 disp("Examine the poles and zeros of the continuous system:");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
144 sysout(sys_cont,"all");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
145 disp("\nTo convert this to a discrete system, a sampling time is needed:");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
146 cmd = "Tsam = 0.5;";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
147 run_cmd;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
148 disp("\nNow convert to a discrete system with the command:");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
149 cmd = "sys_disc = c2d(sys_cont,Tsam);";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
150 run_cmd;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
151 disp("Examine the poles and zeros of the discrete system:");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
152 sysout(sys_disc,"all");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
153 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
154 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
155
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
156 disp("\nNow we will convert the discrete system back to a continuous system");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
157 disp("using the d2c command:");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
158 help d2c
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
159 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
160 cmd = "new_sys_cont = d2c(sys_disc);";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
161 run_cmd;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
162 disp("\nExamine the poles and zeros of the discrete system:");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
163 sysout(new_sys_cont,"all");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
164 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
165
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
166 elseif (k == 4)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
167 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
168 help are
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
169 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
170 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
171
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
172 disp("Algebraic Riccati Equation (are, dare)");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
173
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
174 disp("\nExample #1, consider the continuous state space system:\n");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
175 a=[1, 3, -10.2; 3.7, -2, 9; 1, 3, 7]
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
176 b=[1, 12; 6, 2; -3.8, 7]
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
177 c=[1, -1.1, 7; 3, -9.8, 2]
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
178 d=0
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
179 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
180 disp("\nThe solution to the continuous algebraic riccati equation");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
181 disp("is computed as follows:");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
182 cmd = "x_cont = are(a, b, c);";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
183 run_cmd;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
184 disp("Results:\n")
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
185 x_cont = are(a,b,c)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
186 disp("Variable Description:\n")
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
187 disp("x_cont => solution to the continuous algebraic riccati equation");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
188 disp("a, b, c => a, b, and c matrices of continuous time system\n");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
189 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
190
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
191 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
192 help dare
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
193 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
194 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
195
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
196 disp("Example #2, consider the discrete time state space system:\n");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
197 a=[1, 5, -8.4; 1.2, -3, 5; 1, 7, 9]
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
198 b=[1, 5; 2, 6; -4.4, 5]
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
199 c=[1, -1.5, 2; 6, -9.8, 1]
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
200 d=0
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
201 r=eye(columns(b))
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
202 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
203 disp("\nThe solution to the continuous algebraic riccati equation");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
204 disp("is computed as follows:");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
205 cmd = "x_disc = dare(a, b, c, r);";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
206 run_cmd;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
207 disp("Results:\n")
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
208 x_disc = dare(a,b,c,r)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
209 disp("Variable Description:\n");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
210 disp("x_disc => solution to the discrete algebraic riccati equation");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
211 disp("a, b, c => a, b and c matrices of discrete time system\n");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
212 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
213 clc
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
214
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
215 elseif (k == 5)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
216 disp("--- Balanced realization: not yet implemented")
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
217 elseif (k == 6)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
218 disp("--- Open loop balanced truncation: not yet implemented")
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
219 elseif (k == 7)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
220 disp("SISO pole placement example:")
4771
b8105302cfe8 [project @ 2004-02-16 17:45:50 by jwe]
jwe
parents: 4139
diff changeset
221 cmd = "sys=tf(1, [1, -2, 1]);";
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
222 run_cmd
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
223 disp("System in zero-pole form is:")
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
224 cmd = "sysout(sys,\"zp\");";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
225 run_cmd
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
226 disp("and in state space form:")
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
227 cmd = "sysout(sys,\"ss\");";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
228 run_cmd
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
229 disp("Desired poles at -1, -1");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
230 cmd = "K=place(sys, [-1, -1])";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
231 run_cmd
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
232 disp("Check results:")
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
233 cmd = "[A,B] = sys2ss(sys);";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
234 run_cmd
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
235 cmd = "poles=eig(A-B*K)";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
236 run_cmd
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
237 prompt
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
238 elseif (k == 8)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
239 return
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
240 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
241 endwhile
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
242 endfunction
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
243