Mercurial > octave-nkf
comparison scripts/control/system/syssub.m @ 4771:b8105302cfe8
[project @ 2004-02-16 17:45:50 by jwe]
author | jwe |
---|---|
date | Mon, 16 Feb 2004 17:45:50 +0000 |
parents | 0d411821682c |
children | bdbee5282954 |
comparison
equal
deleted
inserted
replaced
4770:ef5e598f099b | 4771:b8105302cfe8 |
---|---|
47 if(nargin < 1) | 47 if(nargin < 1) |
48 usage("syssub: sys = syssub(Gsys{,Hsys,...})"); | 48 usage("syssub: sys = syssub(Gsys{,Hsys,...})"); |
49 endif | 49 endif |
50 | 50 |
51 ## collect all arguments | 51 ## collect all arguments |
52 arglist = list(); | 52 arglist = {}; |
53 for kk=1:nargin | 53 for kk=1:nargin |
54 arglist(kk) = varargin{kk}; | 54 arglist{kk} = varargin{kk}; |
55 if(!isstruct(nth(arglist,kk))) | 55 if(!isstruct(arglist{kk})) |
56 error("syssub: argument %d is not a data structure",kk); | 56 error("syssub: argument %d is not a data structure",kk); |
57 endif | 57 endif |
58 endfor | 58 endfor |
59 | 59 |
60 ## check system dimensions | 60 ## check system dimensions |
61 [n,nz,mg,pg,Gyd] = sysdimensions(nth(arglist,1)); | 61 [n,nz,mg,pg,Gyd] = sysdimensions(arglist{1}); |
62 for kk=2:nargin | 62 for kk=2:nargin |
63 [n,nz,mh,ph,Hyd] = sysdimensions(nth(arglist,kk)); | 63 [n,nz,mh,ph,Hyd] = sysdimensions(arglist{kk}); |
64 if(mg != mh) | 64 if(mg != mh) |
65 error("arg 1 has %d inputs; arg %d has vs %d inputs",mg,kk,mh); | 65 error("arg 1 has %d inputs; arg %d has vs %d inputs",mg,kk,mh); |
66 elseif(pg != ph) | 66 elseif(pg != ph) |
67 error("arg 1 has %d outputs; arg %d has vs %d outputs",pg,kk,ph); | 67 error("arg 1 has %d outputs; arg %d has vs %d outputs",pg,kk,ph); |
68 elseif(norm(Gyd - Hyd)) | 68 elseif(norm(Gyd - Hyd)) |
71 endif | 71 endif |
72 endfor | 72 endfor |
73 | 73 |
74 ## perform the subtract | 74 ## perform the subtract |
75 if(nargin == 2) | 75 if(nargin == 2) |
76 Gsys = nth(arglist,1); Hsys = nth(arglist,2); | 76 Gsys = arglist{1}; |
77 Hsys = arglist{2}; | |
77 if( strcmp(sysgettype(Gsys),"tf") | strcmp(sysgettype(Hsys),"tf") ) | 78 if( strcmp(sysgettype(Gsys),"tf") | strcmp(sysgettype(Hsys),"tf") ) |
78 ## see if subtracting transfer functions with identical denominators | 79 ## see if subtracting transfer functions with identical denominators |
79 [Gnum,Gden,GT,Gin,Gout] = sys2tf(Gsys); | 80 [Gnum,Gden,GT,Gin,Gout] = sys2tf(Gsys); |
80 [Hnum,Hden,HT,Hin,Hout] = sys2tf(Hsys); | 81 [Hnum,Hden,HT,Hin,Hout] = sys2tf(Hsys); |
81 if(length(Hden) == length(Gden) ) | 82 if(length(Hden) == length(Gden) ) |
82 if( (Hden == Gden) & (HT == GT) ) | 83 if( (Hden == Gden) & (HT == GT) ) |
83 sys = tf2sys(Gnum-Hnum,Gden,GT,Gin,Gout); | 84 sys = tf(Gnum-Hnum,Gden,GT,Gin,Gout); |
84 return | 85 return |
85 endif | 86 endif |
86 ## if not, we go on and do the usual thing... | 87 ## if not, we go on and do the usual thing... |
87 endif | 88 endif |
88 endif | 89 endif |
104 | 105 |
105 sys = sysscale (sys, [eyout, -eyout], [eyin; eyin], Gout, Gin); | 106 sys = sysscale (sys, [eyout, -eyout], [eyin; eyin], Gout, Gin); |
106 | 107 |
107 else | 108 else |
108 ## multiple systems (or a single system); combine together one by one | 109 ## multiple systems (or a single system); combine together one by one |
109 sys = nth(arglist,1); | 110 sys = arglist{1}; |
110 for kk=2:length(arglist) | 111 for kk=2:length(arglist) |
111 sys = syssub(sys,nth(arglist,kk)); | 112 sys = syssub(sys,arglist{kk}); |
112 endfor | 113 endfor |
113 endif | 114 endif |
114 | 115 |
115 endfunction | 116 endfunction |