From 14e9e99b0be854c207a8069a3f14f87691f33f23 Mon Sep 17 00:00:00 2001 From: nandard Date: Thu, 8 Sep 2022 03:24:34 +0700 Subject: [PATCH] Add documentation --- README.md | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 40b9120..7ef422a 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,45 @@ Libraries that used in this program is ```numpy``` and ```pandas```. ```numpy``` ``` import numpy as np import pandas as pd -``` \ No newline at end of file +``` + +## RouthStability Class +This class contains lots of procedures to simplify our Routh Stability Table Generator process. +``` +def __init__(self, den): + self.den = np.array([float(item) for item in den.split()]) + self.deg = len(self.den) +``` +The constructor ```__init__``` takes string of coefficiens from polynomial, extract the number, and load into class variable. It also define ```self.deg``` variable to save array's length, reducing number of calling ```len()``` function + +``` +def set_k(self, k): + self.den = np.append(self.den, float(k)) + self.deg += 1 +``` +This function only takes one number from user and append it to ```self.den``` which defined as gain (constant). Also ```self.deg``` will increase by one + +``` +def calc_routh(self): + height = (self.deg+1)//2 + arr = np.zeros((height + 2,height)) + for index in range(self.deg): + if index % 2 == 0: + arr[0][index//2] = self.den[index] + else: + arr[1][(index-1)//2] = self.den[index] + + for i in range(2, height+2): + for j in range(height-1): + arr[i][j] = (arr[i-1][0]*arr[i-2][j+1] - arr[i-2][0]*arr[i-1][j+1])//2 + arr[i][j] += 0 + + self.df = pd.DataFrame(arr) + self.show_tab() + if self.is_stable() == True: + print("SYSTEM IS STABLE") + 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 +$$ 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]} $$