comparison scripts/control/system/sysupdate.m @ 7136:59dcf01bb3e3

[project @ 2007-11-08 20:18:25 by jwe]
author jwe
date Thu, 08 Nov 2007 20:18:26 +0000
parents a1dbe9d80eee
children
comparison
equal deleted inserted replaced
7135:8aa770b6c5bf 7136:59dcf01bb3e3
57 function sys = sysupdate (sys, opt) 57 function sys = sysupdate (sys, opt)
58 58
59 ## check for correct number of inputs 59 ## check for correct number of inputs
60 if (nargin != 2) 60 if (nargin != 2)
61 print_usage (); 61 print_usage ();
62 elseif(! isstruct(sys) ) 62 elseif (! isstruct (sys))
63 error("1st argument must be system data structure") 63 error ("first argument must be system data structure");
64 elseif(! (strcmp(opt,"tf") + strcmp(opt,"zp") + ... 64 elseif (! (strcmp (opt, "tf") || strcmp (opt, "zp")
65 strcmp(opt,"ss") + strcmp(opt,"all")) ) 65 || strcmp (opt, "ss") || strcmp (opt, "all")))
66 error("2nd argument must be \"tf\", \"zp\", \"ss\", or \"all\""); 66 error ("second argument must be \"tf\", \"zp\", \"ss\", or \"all\"");
67 endif 67 endif
68 68
69 ## check to make sure not trying to make a SISO system out of a MIMO sys 69 ## check to make sure not trying to make a SISO system out of a MIMO sys
70 if ( (strcmp(opt,"tf") + strcmp(opt,"zp") + strcmp(opt,"all")) ... 70 if ((strcmp (opt, "tf") || strcmp(opt,"zp") || strcmp (opt, "all"))
71 & strcmp(sysgettype(sys),"ss") & (! is_siso(sys) ) ) 71 && strcmp (sysgettype (sys), "ss") && ! is_siso (sys))
72 error("MIMO -> SISO update requested"); 72 error ("MIMO -> SISO update requested");
73 endif 73 endif
74 74
75 ## update transfer function if desired 75 ## update transfer function if desired
76 if ( (strcmp(opt, "tf") + strcmp(opt,"all"))&& (!sys.sys(2))) 76 if ((strcmp (opt, "tf") || strcmp (opt, "all")) && (! sys.sys(2)))
77 ## check to make sure the system is not discrete and continuous 77 ## check to make sure the system is not discrete and continuous
78 is_digital(sys); 78 is_digital (sys);
79 79
80 ## if original system zero-pole 80 ## if original system zero-pole
81 if strcmp(sysgettype(sys),"zp") 81 if (strcmp (sysgettype (sys), "zp"))
82 [sys.num,sys.den] = zp2tf(sys.zer,sys.pol,sys.k); 82 [sys.num, sys.den] = zp2tf (sys.zer, sys.pol, sys.k);
83 sys.sys(2) = 1; 83 sys.sys(2) = 1;
84 ## if original system is state-space 84 ## if original system is state-space
85 elseif(sys.sys(1) == 2) 85 elseif (sys.sys(1) == 2)
86 [sys.num,sys.den] = ss2tf(sys.a,sys.b,sys.c,sys.d); 86 [sys.num, sys.den] = ss2tf (sys.a, sys.b, sys.c, sys.d);
87 sys.sys(2) = 1; 87 sys.sys(2) = 1;
88 endif 88 endif
89 endif 89 endif
90 90
91 91
92 ## update zero-pole if desired 92 ## update zero-pole if desired
93 if ( (strcmp(opt, "zp") + strcmp(opt,"all")) && (! sys.sys(3)) ) 93 if ((strcmp (opt, "zp") || strcmp (opt, "all")) && ! sys.sys(3))
94 ## check to make sure the system is not discrete and continuous 94 ## check to make sure the system is not discrete and continuous
95 is_digital(sys); 95 is_digital (sys);
96 96
97 ## original system is transfer function 97 ## original system is transfer function
98 if (sys.sys(1) == 0) 98 if (sys.sys(1) == 0)
99 [sys.zer,sys.pol,sys.k] = tf2zp(sys.num,sys.den); 99 [sys.zer, sys.pol, sys.k] = tf2zp (sys.num, sys.den);
100 sys.sys(3) = 1; 100 sys.sys(3) = 1;
101 ## original system is state-space 101 ## original system is state-space
102 102 elseif (sys.sys(1) == 2)
103 elseif(sys.sys(1) == 2) 103 [sys.zer, sys.pol, sys.k] = ss2zp (sys.a, sys.b, sys.c, sys.d);
104 [sys.zer,sys.pol,sys.k] = ss2zp(sys.a,sys.b,sys.c,sys.d);
105 sys.sys(3) = 1; 104 sys.sys(3) = 1;
106 endif 105 endif
107
108 endif 106 endif
109 107
110 ## update state-space if desired 108 ## update state-space if desired
111 if ( (strcmp(opt, "ss") + strcmp(opt,"all")) && (! sys.sys(4)) ) 109 if ((strcmp (opt, "ss") || strcmp (opt, "all")) && ! sys.sys(4))
112 ## original system is transfer function 110 ## original system is transfer function
113 if (sys.sys(1) == 0) 111 if (sys.sys(1) == 0)
114 [sys.a,sys.b,sys.c,sys.d] = tf2ss(sys.num,sys.den); 112 [sys.a, sys.b, sys.c, sys.d] = tf2ss (sys.num, sys.den);
115 sys.sys(4) = 1; 113 sys.sys(4) = 1;
116 ## original system is zero-pole 114 ## original system is zero-pole
117 elseif(sys.sys(1) == 1) 115 elseif (sys.sys(1) == 1)
118 [sys.a,sys.b,sys.c,sys.d] = zp2ss(sys.zer,sys.pol,sys.k); 116 [sys.a, sys.b, sys.c, sys.d] = zp2ss (sys.zer, sys.pol, sys.k);
119 sys.sys(4) = 1; 117 sys.sys(4) = 1;
120 endif 118 endif
121 119
122 ## create new state names 120 ## create new state names
123 sys.stname = __sysdefstname__ (sys.n, sys.nz); 121 sys.stname = __sysdefstname__ (sys.n, sys.nz);