-
Notifications
You must be signed in to change notification settings - Fork 1
/
initial_cheenu.sci
443 lines (404 loc) · 13.3 KB
/
initial_cheenu.sci
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
//this is the actual file initial4
//work on this only
function[varargout]=initial(varargin)
n=length(varargin);
m=length(varargout);
[lhs,rhs]=argn(0)
if(typeof(varargin(1))<>'state-space') then
error('wrong input argument .Enter state space model only' )
end
k=0;
//////////determining no. of constants///////////////
for j=1:rhs
if(typeof(varargin(j))=='constant') then
k=k+1;
end
end
/////////////getting subplot credentiALA////////////
/////////////////////////////////////////////////////////
///////////////////////////////////////////////////
//disp(k);
///////if two constants///////////////////////////////////////time & x0 specification part//////////
if (k==2) then
x0=varargin(n-1);///////second last as initial condition///////////
//disp(x0);
if typeof(varargin($)) == 'constant' then /////time//////////
if size(varargin($)) == [1 1] then
if varargin($) <= 0 then
error(msprintf(gettext("%s: The final time value must be a positive real number.\n"),"stepplot"))
end
tFinal = varargin($)
totalTime =0:0.01:tFinal;
elseif isequal(size(varargin($)),[1 1]) == %f then
// finding that the time vector has positive time value
tempTimeIndex = find(varargin($) >= 0)
if isequal(size(varargin($)),size(tempTimeIndex)) == %t then
totalTime = varargin($)
for l=1:(n-2)
if(typeof(varargin(l))==['state-space'] & varargin(l).dt<>'c') then
if(varargin(l).dt=='d') then
t=1; /////////if 'd' then the sampling time is 1
else
t=varargin(l).dt
end
if(t<>(totalTime(2)-totalTime(1))) then
error('time interval must be equal to sampling time')
else
totalTime=0:t:totalTime($)
end
end
end
else
////////////here also we should check dt but lets do it later---""CHEENU""/////////////////
tempTime = varargin($)
tempTime = tempTime(tempTimeIndex(1):tempTimeIndex($))
totalTime = tempTime
end
end
end
elseif(k==1) then //////////////////if time is not specified/////////////////////////
x0=varargin($);
end
///////////////////////////////////////////////////////////////////////////////
ll=0;
for j=1:rhs-k
xx1(j)=size(varargin(j),'r');
//// if(typeof(varargin(j))=='state-space') then
//// bb=varargin(j).a
//// if(size(x0,'r')==size(bb,'r')) then
//// ll=ll+1;
//// else
//// error('wrong size of initial condition');
//// end
////end
////end
////tl=find(typeof(varargin(j))=='state-space');
////if (size(tl,'c')==ll) then
//// disp('paro')
////else
//// disp('cheenu')
end
index=1;
for i=1:(n-k)
index=index+1;
if(typeof(varargin(i))=='string') then
continue;
end
[row col]=size(x0);
if(typeof(varargin(i))==['state-space'] & col==1) then
[a b c d] = abcd(varargin(i));
///////////checking matrix sizes////////////////
if(size(b)<>[mtlb_size(a,1),mtlb_size(d,2)]| size(c)<>[mtlb_size(d,1),mtlb_size(a,2)]| size(d)<>[mtlb_size(c,1),mtlb_size(b,2)]|size(varargin(i).a,'r')<>row) then
error('wrong size of matrices')
else
//b1 = zeros(mtlb_size(a,1),mtlb_size(d,2));
d1 = zeros(mtlb_size(c,1),mtlb_size(x0,2));
c1 = zeros(mtlb_size(d,1),mtlb_size(a,2));
end
if(((varargin(i).dt)=='c')) then
sys=syslin('c',a,x0,c1,d1);
if (k==1) then
pq=pole(varargin(i))
pq=cell2mat(pq);
mm=real(pq);
//qq= find(pq>0)
t1=0:0.1:100;
if or(mm>0) then
totalTime=t1;
// [aa,x]=csim('impuls',t1,sys)
// aa=c*x;
else
[aa,x]=csim('impuls',t1,sys)
aa=c*x;
tt=find(aa>0.002);
totalTime=0:0.1:t1(tt($))
end
[aa,x]=csim('impuls',totalTime,sys)
aa=c*x;
else
//sys=syslin('c',a,x0,c1,d1);
[aa,x]=csim('impuls',totalTime,sys);
aa=c*x;
end
else /////////////////this else is of string and continuous therefore for discrete//////////////////////
if (k==1) then
pq=pole(varargin(i));
pq=cell2mat(pq);
t1=0:0.1:100;
mm=real(pq);
if(varargin(i).dt=='d') then
dtime=1;
else
dtime=varargin(i).dt;
end
if or(mm>0) then
// disp('paro')
totalTime=0:dtime:100;
//disp('paro')
// [aa,x]=ltitr(a,b,zeros(1,length(totalTime)),x0);
// aa=c*x;
elseif and(mm<0) then
[aa,x]=ltitr(a,b,zeros((size(b,'c')),length(t1)),x0);
aa=c*x;
tt=find(or(aa>=0.002))
totalTime=0:dtime:t1(tt($));
end
[aa,x]=ltitr(a,b,zeros(size(b,'c'),length(totalTime)),x0);
aa=c*x;
else
[aa,x]=ltitr(a,b,zeros(size(b,'c'),length(totalTime)),x0);
aa=c*x;
end
end
elseif(typeof(varargin(i))<>['string']) then
error('wrong type of initial condition entered');
end
////////////////////////////plotting//////////////
if (lhs==1) then
if (size(varargin(i))==[1 1]) then
if(typeof(varargin(i+1))=='string') then
plot(totalTime,aa,varargin(i+1));
hh=gce();
if(varargin(i).dt<>'c') then
hh.children.polyline_style=2;
end
else
plot(totalTime,aa)
hh=gce();
hh.children.foreground=index;
if(varargin(i).dt<>'c') then
hh.children.polyline_style=2;
end
end
else
//xx=size(aa,'r');
xx=size(varargin(i),'r');
Q=1;
if(typeof(varargin(i+1))=='string') then
for oo=1:xx
// for pp=1:yy
subplot(max(xx1),1,Q)
Q=Q+1;
plot(totalTime,aa(oo,:),varargin(i+1))
if(varargin(i).dt<>'c') then
hh=gce();
hh.children.polyline_style=2;
end
end
// end
else
for oo=1:xx
//for pp=1:yy
subplot(max(xx1),1,Q)
Q=Q+1;
plot(totalTime,aa(oo,:))
hh=gce();
hh.children.foreground=index;
if(varargin(i).dt<>'c') then
hh.children.polyline_style=2;
end
//end
end
end
end
//end
h=gcf();
h.figure_name="INITIAL_RESPONSE";
varargout(1)="INITIAL_RESPONSE"
//end
/////////fot ends here////////////////
/////////////more than one output argument///////////////////////
elseif(lhs>1) then
if((lhs==2)|(lhs==3)) then
varargout(1)=aa;
varargout(2)=totalTime;
if(lhs==3) then
varargout(3)=x;
end
end
end
end
endfunction
//if (size(varargin(i))==[1 1]) then
// if(typeof(varargin(i+1))=='string') then
// plot(totalTime,aa,varargin(i+1));
// hh=gce();
// if(varargin(i).dt<>'c') then
// hh.children.polyline_style=2;
// end
// else
// plot(totalTime,aa)
// hh=gce();
// if(varargin(i).dt<>'c') then
// hh.children.polyline_style=2;
// end
// end
//else
// xx=size(varargin(i),'r');
// yy=size(varargin(i),'c');
// Q=1;
// if(typeof(varargin(i+1))=='string') then
// if(varargin(i).dt=='c') then
// for oo=1:xx
// for pp=1:yy
// subplot(xx,yy,Q)
// Q=Q+1;
// plot(totalTime,aa,varargin(i+1))
// end
// end
// else
// for oo=1:xx
// for pp=1:yy
// subplot(xx,yy,Q)
// Q=Q+1;
// plot(totalTime,aa,varargin(i+1));
// hh=gce();
// hh.children.polyline_style=2;
//end
//end
//end
//else
// if(varargin(i).dt=='c') then
//
// for oo=1:xx
// //for pp=1:yy
//
// subplot(xx,yy,Q)
// Q=Q+1;
// plot(totalTime,aa)
//end
// else
// for oo=1:xx
// //for pp=1:yy
// subplot(max(oo),max(pp),Q)
// Q=Q+1;
// plot(totalTime,aa);
// hh=gce();
// hh.children.polyline_style=2;
//end
//end
//end
//end
//
//h=gcf();
//h.figure_name="INITIAL_RESPONSE";
//varargout(1)="INITIAL_RESPONSE"
////end
///////////fot ends here////////////////
//
///////////////more than one output argument///////////////////////
//else
// if((lhs==2)|(lhs==3)) then
// varargout(1)=aa;
// varargout(2)=totalTime;
// if(lhs==3) then
//
// varargout(3)=x;
// end
// end
//end
//end
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// if(typeof(varargin(1))<>'state-space') then
// error('wrong input argument .Enter state space model only' )
// end
// k=0;
// for j=1:rhs
// if(typeof(varargin(j))=='constant')
// k=k+1;
// end
// end
// if (k==2) then
// x0=varargin($-1);
// if size(varargin($)) == [1 1] then
// if varargin($) <= 0 then
// error("the final time value must be positive no.")
// end
// tFinal = varargin($)
// totalTime =0:0.01:tFinal;
// elseif isequal(size(varargin($)),[1 1]) == %f then
// // finding that the time vector has positive time value
// tempTimeIndex = find(varargin($) >= 0)
// if isequal(size(varargin($)),size(tempTimeIndex)) == %t then
// t= varargin($);
// for u=1:n
// if(((varargin(u)).dt<>'c')& typeof(varargin(u))<>'constant') then
// dt=varargin(u).dt;
// if(t(tempTimeIndex(2))-t(tempTimeIndex(1))<>dt) then
// error('time interval must be equal to sampling time')
// else
// t=0:dt:t(tempTimeIndex($));
// end
// end
//
// end
//
// else
// tempTime = varargin($)
// tempTime = tempTime(tempTimeIndex(1):tempTimeIndex($))
// totalTime = tempTime
// end
// end
// end
//
// end
//else if(k==1) then
// xo=varargin($) ;
// totalTime=0:0.1:3;
// end
// for i=1:n-k
// [a b c d] = abcd(varargin(i));
// if(size(b)<>[mtlb_size(a,1),mtlb_size(d,2)]| size(c)<>[mtlb_size(d,1),mtlb_size(a,2)]| size(d)<>[mtlb_size(c,1),mtlb_size(b,2)]) then
// error('wrong size of matrices')
//else
// //b1 = zeros(mtlb_size(a,1),mtlb_size(d,2));
// d1 = zeros(mtlb_size(c,1),mtlb_size(x0,2));
// c1 = zeros(mtlb_size(d,1),mtlb_size(a,2));
//
// end
// if(varargin(i).dt=='c') then
// varargin(i)=syslin('c',a,x0,c1,d1);
// [aa,x]=csim('impuls',totalTime,varargin(i));
// aa=c*x;
//
// else
// [aa,x]=ltitr(a,b,zeros(1,length(totalTime)),x0);
// aa=c*x;
//// for i=1:length(totalTime);
////
////end
//end
// else
// error('wrong type of initial condition entered');
//end
//plot(totalTime,aa)
//end
//if(lhs>1) then
// if((lhs==2)|(lhs==3)) then
// varargout(1)=aa;
// varargout(2)=totalTime;
// if(lhs==3) then
// varargout(3)=x;
// end
// end
//end
//
//endfunction
/////////////////////////
//for op=1:rhs-1
// sys1=ss2tf(varargin(i))
// pq=pole(sys)
//if (pq>0) then
//t=100;
//totalTime=0:1:100;
//else
//aa=0.02*aa;
//0.2*aa=csim('impuls',)
//
/// for i=1:2
//[a b c d]=abcd(op(i));
// t=0:op(i).dt:5
//[aa,x]=ltitr(a,b,zeros(1,length(t)),[4;5])
//end