This commit is contained in:
nandard 2022-09-08 03:41:49 +07:00
parent ecc811338a
commit 82ffcee655

View File

@ -46,6 +46,62 @@ def calc_routh(self):
else:
print("SYSTEM IS UNSTABLE")
```
```calc_routh(self)``` as the core process of this class contains initialization and process about Routh Stability Process. Firstly, it define an empty zero (basically it filled with zeros) and iteratively being inserted by ```self.den``` (refering to Routh Table principle). After that, each cell will be updated by calculating Routh Table formula
```calc_routh(self)``` as the core process of this class contains initialization and process about Routh Stability Process. Firstly, it define an empty zero (basically it filled with zeros) and iteratively being inserted by ```self.den``` (refering to Routh Table principle). After that, each cell will be updated by calculating Routh Table formula. Routh Table defined as ```numpy.ndarray``` and converted to ```pandas.DataFrame``` to simplify the presentation of table. ```self.show_tab()``` is called to print the Routh Table and ```self.is_stable()``` to check system's stability.
$arr_{i,j}=\frac{arr_{i-1][0]*arr[i-2][j+1]-arr[i-2][0]*arr[i-1][j+1]}{arr_{i-1][0]}$/
```
def show_tab(self):
print(self.df)
```
This function print the Routh Table, should be called only if Routh Table is generated by ```calc_routh```
```
def get_table(self):
return self.df
```
This function return ```pandas.DataFrame``` contained by Routh Table
```
def is_stable(self):
flag = True
for item in self.df[0]:
if item < 0: flag = False
return flag
```
This function check the first column's value from Routh Table. The system is define as stable if and only if all the value is positive, else it's unstable
```
def get_poly(self, x):
total = 0
for i in range(self.deg):
total += self.den[self.deg-i-1]*(x**i)
print(total)
return total
```
This function initialize ```x``` value as variable on ```self.den``` polynomial and return the total
## Testing
The testing can follow below example:
```
# First Testing
den = input("Enter your polynomial: ")
k_in = input("Enter your K: ")
rs = RouthStability(den)
rs.set_k(k_in)
rs.calc_routh()
```
It takes coefficient of polynomial and K from user, insert it into ```RouthStability``` class as constructor parameter, insert the K value, and generate Routh Table. The result can be found below:
```
Enter your polynomial: 1 2 3 4 5
Enter your K: 6
0 1 2
0 1.0 3.0 5.0
1 2.0 4.0 6.0
2 1.0 2.0 0.0
3 0.0 3.0 0.0
4 -2.0 0.0 0.0
SYSTEM IS UNSTABLE
```
### Notes
Contact nanda.r.d@mail.ugm.ac.id for more information