-
Notifications
You must be signed in to change notification settings - Fork 0
/
RouthCriteria.m
111 lines (85 loc) · 3.18 KB
/
RouthCriteria.m
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
classdef RouthCriteria
properties
rowz;
itterations;
system;
end
methods
function generate_rows(obj)
new_rows=obj.rowz;
append_row=zeros(1,height(new_rows));
itter= (obj.itterations)-2;
y=width(new_rows);
order=strings(1:obj.itterations);
append_row=zeros(itter,width(new_rows));
for j=1:obj.itterations %%set the indexes of table i.e s^4 s^3 etc
pow=j-1;
order(j)=sym('s')^string(pow);
end
for i=1:itter %%excute routh criteria
try
for p= 1:y
mul1=new_rows((i+1),p);
mul2=new_rows((i),(p+1));
mul3=new_rows((i),(p));
mul4=new_rows((i+1),(p+1));
num2=(mul1*mul2)-(mul3*mul4);
new = num2/new_rows((i+1),p);
append_row(i,p)=new;
end
catch
append_row(i,p)=0;
end
%%special case when a whole row equal zeros take derivative
%%aux
if 1/poly2sym(append_row(i,:))==inf && i~=obj.itterations-2
aux_list=[];
counter=1;
for k=1:length(new_rows)
aux_list(counter)=new_rows(end,k);
aux_list(counter+1)=0;
counter=counter+2;
end
aux_list=aux_list(1:length(aux_list)-1);
maxlen=max(height(new_rows));
aux_sys =poly2sym(aux_list);
aux_sym= fliplr(coeffs(diff(aux_sys)));
aux_sym(end+1)=0;
append_row(i,:)=aux_sym;
end
%%special case when a first element is zero ,, make it
%%epcilon
if p ==1 && append_row(i,1)==0 && i~=obj.itterations-2
append_row(i,1)=[0.0001];
end
new_rows=[new_rows;append_row(i,:)];
end
%%setup table
index=[flip(order(1:obj.itterations))];
Routh_table=table(transpose(index),new_rows);
disp(Routh_table)
%%count sign changes to check stability
count=0;
for k=1:height(new_rows)
try
if new_rows(k,1)<0 && new_rows(k+1,1)>0
count=count+1;
end
catch
if new_rows(k,1)<0 && k==height(new_rows) && new_rows(k-1,1)>0
count=count+1;
end
end
end
if count>0
fprintf("system is unstable with %d real positive poles",count)
else
fprintf("system is stable")
end
try
rlocus(obj.system)
catch
end
end
end
end