1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
## Copyright (C) 1996, 2000, 2004, 2005, 2007
## Auburn University. All rights reserved.
##
##
## This program is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; see the file COPYING. If not, see
## <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {Function File} {} moddemo (@var{inputs})
## Octave Control toolbox demo: Model Manipulations demo.
## @end deftypefn
## Author: David Clem
## Created: August 15, 1994
## a s hodel: updated to reflect updated output order in ss2zp
function moddemo ()
while (1)
clc
disp("Octave Model Manipulations Demo")
disp("=======================================")
disp(" 1) Perform continuous to discrete time conversion (c2d)")
disp(" 2) Convert from state space to zero / pole form (ss2zp)")
disp(" Convert from zero / pole to state space form (zp2ss)")
disp(" 3) Convert from state space to transfer function form (ss2tf)")
disp(" Convert from transfer function to state space form (tf2ss)")
disp(" 4) Convert from transfer function to zero / pole form (tf2zp)")
disp(" Convert from zero / pole to transfer function form (zp2tf)")
disp(" 5) Return to main demo menu")
disp(" ")
k=6;
while(k > 5 || k < 1)
k = input("Please enter a number:");
endwhile
if (k == 1)
clc
disp("Perform continuous to discrete time conversion (c2d)\n")
disp("Example #1, Consider the following continuous time state space system:\n")
a=[0, 1; -25, -4]
b=[0; 1]
c=[1, 1]
d=1
prompt
disp("\nTo convert this to a discrete time system (using a zero order hold),")
disp("use the following commands:\n")
cmd="sys=ss(a,b,c,d);";
run_cmd
cmd="dsys = c2d(sys,0.2);";
run_cmd
cmd="sysout(dsys);";
run_cmd
disp("Function check\n")
disp("Check the poles of sys vs dsys:\n")
cmd="[da,db]=sys2ss(dsys);";
run_cmd
cmd="lam = eig(a);";
run_cmd
disp("Discretize the continuous time eigenvalues using the matrix exponential:\n")
disp("lambc = exp(lam*0.2)\n")
lambc = exp(lam*0.2)
disp("Check the eigenvalues of da\n")
lambd = eig(da)
disp("Calculate the difference between lambd and lambc:\n")
cmd = "error = sort(lambd)-sort(lambc)\n";
run_cmd
disp("The error is on the order of roundoff noise, so we're o.k.")
prompt
clc
elseif (k == 2)
clc
disp("Convert from state space to zero / pole form (ss2zp)\n")
disp("Example #1, Consider the following state space system:\n")
a=[0, 3, 1; -2, -4, 5; 5, 8, 2]
b=[0; 5; 2.5]
c=[6, -1.9, 2]
d=[-20]
prompt
disp(" ")
disp("\nTo find the poles and zeros of this sytstem, use the following command:\n")
disp("\n[zer, pol] = ss2zp(a, b, c, d)\n")
prompt
disp("Results:\n")
[zer, pol] = ss2zp(a, b, c, d)
disp("Variable Description:\n")
disp("zer, pol => zeros and poles of the state space system")
disp("a, b, c, d => state space system\n")
prompt
clc
disp("Convert from zero / pole to state space form (zp2ss)\n")
disp("Example #1, Consider the following set of zeros and poles:\n")
zer
pol
prompt
disp("\nTo find an equivalent state space representation for this set of poles")
disp("and zeros, use the following commands:\n")
k=1
disp("\n[na, nb, nc, nd] = zp2ss(zer, pol, k)\n")
prompt
disp("Results:\n")
[na, nb, nc, nd] = zp2ss(zer, pol, k)
disp("Variable Description:\n")
disp("na, nb, nc, nd => state space system equivalent to zero / pole input")
disp("zer, pol => zeros and poles of desired state space system")
disp("k => gain associated with the zeros\n")
prompt
disp("Function check\n")
disp("Are the eigenvalues of the origonal state space system the same as the")
disp("eigenvalues of the newly constructed state space system ?\n")
disp("Find the difference between the two sets of eigenvalues")
disp("error = sort(eig(a)) - sort(eig(na))\n")
error = sort(eig(a)) - sort(eig(na))
prompt
clc
elseif (k == 3)
clc
disp("Convert from state space to transfer function (ss2tf)\n")
disp("Example #1, Consider the following state space system:\n")
a=[0, 1; -2, -3]
b=[1; 1]
c=[1, 9]
d=[1]
prompt
disp("\nTo find an equivalent transfer function for this system, use")
disp("the following command:\n")
disp("[num, den] = ss2tf(a, b, c, d)\n")
prompt
disp("Results:\n")
[num,den] = ss2tf(a, b, c, d)
disp("Variable Description:\n")
disp("num, den => numerator and denominator of transfer function that is")
disp(" equivalent to the state space system")
disp("a, b, c, d => state space system\n")
prompt
clc
disp("Convert from transfer function to state space form (tf2ss)\n")
disp("Example #1, Consider the following transfer function:\n")
num
den
prompt
disp("\nTo find an equivalent state space representation for this system, use")
disp("the following command:\n")
disp("[a, b, c, d] = tf2ss(num, den)\n")
prompt
disp("Results:\n")
[a, b, c, d] = tf2ss(num, den)
disp("Variable Description:\n")
disp("a, b, c, d => state space system equivalent to transfer function input")
disp("num, den => numerator and denominator of transfer function that is equivalent")
disp(" to the state space system\n")
prompt
clc
elseif (k == 4)
clc
disp("Convert from transfer function to zero / pole form (tf2zp)\n")
disp("Example #1, Consider the following transfer function:\n")
num=[1, 2, 3, 4, 5, ]
den=[1, 2, 3, 4, 5, 6, 7]
prompt
disp("\nTo find the zeros and poles of this system, use the following command:\n")
disp("[zer,pol] = tf2zp(num,den)\n")
prompt
disp("Results:\n")
[zer,pol] = tf2zp(num,den)
disp("Variable Description:\n")
disp("zer,pol => zeros and poles of the transfer function")
disp("num, den => numerator and denominator of transfer function\n")
prompt
clc
disp("Convert from zero / pole to transfer function (zp2tf)\n")
disp("Example #1, Consider the following set of zeros and poles:\n")
zer
pol
prompt
disp("\nTo find an equivalent transfer function representation for this set")
disp("of poles and zeros, use the following commands:\n")
k=1
disp("\n[num, den] = zp2tf(zer, pol, k)\n")
prompt
disp("Results:\n")
[num, den] = zp2tf(zer, pol, k)
disp("Variable Description:\n")
disp("[num, den] => transfer function representation of desired set of zeros")
disp(" and poles")
disp("a, b, c, d => state space system")
disp("zer, pol => zeros and poles of desired state space system")
disp("k => gain associated with the zeros\n")
prompt
clc
elseif (k == 5)
return
endif
endwhile
endfunction
|