Correct slight space

This commit is contained in:
nandard 2022-09-08 03:07:03 +07:00
parent f2556fd7ba
commit 4a8b20b378

View File

@ -1,32 +1,17 @@
{ {
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 132,
"metadata": {
"id": "aDtFkeqAvLX2"
},
"outputs": [],
"source": [ "source": [
"# Import Libraries\n", "# Import Libraries\n",
"import numpy as np\n", "import numpy as np\n",
"import pandas as pd" "import pandas as pd"
], ]
"metadata": {
"id": "aDtFkeqAvLX2"
},
"execution_count": 132,
"outputs": []
}, },
{ {
"cell_type": "code", "cell_type": "code",
@ -38,14 +23,17 @@
"source": [ "source": [
"# Define RouthStability Class \n", "# Define RouthStability Class \n",
"class RouthStability():\n", "class RouthStability():\n",
"\n",
" ## constructor takes string of coefficiens from polynomial\n", " ## constructor takes string of coefficiens from polynomial\n",
" def __init__(self, den):\n", " def __init__(self, den):\n",
" self.den = np.array([float(item) for item in den.split()])\n", " self.den = np.array([float(item) for item in den.split()])\n",
" self.deg = len(self.den)\n", " self.deg = len(self.den)\n",
"\n",
" ## append k as constant in array\n", " ## append k as constant in array\n",
" def set_k(self, k):\n", " def set_k(self, k):\n",
" self.den = np.append(self.den, float(k))\n", " self.den = np.append(self.den, float(k))\n",
" self.deg += 1\n", " self.deg += 1\n",
"\n",
" ## generate routh table and print its state\n", " ## generate routh table and print its state\n",
" def calc_routh(self):\n", " def calc_routh(self):\n",
" height = (self.deg+1)//2\n", " height = (self.deg+1)//2\n",
@ -67,18 +55,22 @@
" print(\"SYSTEM IS STABLE\")\n", " print(\"SYSTEM IS STABLE\")\n",
" else:\n", " else:\n",
" print(\"SYSTEM IS UNSTABLE\")\n", " print(\"SYSTEM IS UNSTABLE\")\n",
"\n",
" ## print generated route table\n", " ## print generated route table\n",
" def show_tab(self):\n", " def show_tab(self):\n",
" print(self.df)\n", " print(self.df)\n",
"\n",
" ## return generated route DataFrame\n", " ## return generated route DataFrame\n",
" def get_table(self):\n", " def get_table(self):\n",
" return self.df\n", " return self.df\n",
"\n",
" ## return system stability as boolean\n", " ## return system stability as boolean\n",
" def is_stable(self):\n", " def is_stable(self):\n",
" flag = True\n", " flag = True\n",
" for item in self.df[0]:\n", " for item in self.df[0]:\n",
" if item < 0: flag = False\n", " if item < 0: flag = False\n",
" return flag\n", " return flag\n",
" \n",
" ## return the value of a polynomial\n", " ## return the value of a polynomial\n",
" def get_poly(self, x):\n", " def get_poly(self, x):\n",
" total = 0\n", " total = 0\n",
@ -90,27 +82,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "execution_count": 134,
"# First Testing\n",
"den = input(\"Enter your polynomial: \")\n",
"k_in = input(\"Enter your K: \")\n",
"\n",
"rs = RouthStability(den)\n",
"rs.set_k(k_in)\n",
"rs.calc_routh()"
],
"metadata": { "metadata": {
"id": "Je19fGrvtOu4",
"colab": { "colab": {
"base_uri": "https://localhost:8080/" "base_uri": "https://localhost:8080/"
}, },
"id": "Je19fGrvtOu4",
"outputId": "c99b1159-f745-4c3f-c012-c2f464b8edb0" "outputId": "c99b1159-f745-4c3f-c012-c2f464b8edb0"
}, },
"execution_count": 134,
"outputs": [ "outputs": [
{ {
"output_type": "stream",
"name": "stdout", "name": "stdout",
"output_type": "stream",
"text": [ "text": [
"Enter your polynomial: 1 2 3 4 5\n", "Enter your polynomial: 1 2 3 4 5\n",
"Enter your K: 6\n", "Enter your K: 6\n",
@ -123,19 +106,20 @@
"SYSTEM IS UNSTABLE\n" "SYSTEM IS UNSTABLE\n"
] ]
} }
] ],
},
{
"cell_type": "code",
"source": [ "source": [
"# Second Testing\n", "# First Testing\n",
"den = input(\"Enter your polynomial: \")\n", "den = input(\"Enter your polynomial: \")\n",
"k_in = input(\"Enter your K: \")\n", "k_in = input(\"Enter your K: \")\n",
"\n", "\n",
"rs = RouthStability(den)\n", "rs = RouthStability(den)\n",
"rs.set_k(k_in)\n", "rs.set_k(k_in)\n",
"rs.calc_routh()" "rs.calc_routh()"
], ]
},
{
"cell_type": "code",
"execution_count": 136,
"metadata": { "metadata": {
"colab": { "colab": {
"base_uri": "https://localhost:8080/" "base_uri": "https://localhost:8080/"
@ -143,11 +127,10 @@
"id": "kFgcxNcscafI", "id": "kFgcxNcscafI",
"outputId": "25aadcc4-6a29-4c16-c992-46d95a56cbfb" "outputId": "25aadcc4-6a29-4c16-c992-46d95a56cbfb"
}, },
"execution_count": 136,
"outputs": [ "outputs": [
{ {
"output_type": "stream",
"name": "stdout", "name": "stdout",
"output_type": "stream",
"text": [ "text": [
"Enter your polynomial: 12 56 37 80\n", "Enter your polynomial: 12 56 37 80\n",
"Enter your K: 17\n", "Enter your K: 17\n",
@ -160,19 +143,20 @@
"SYSTEM IS STABLE\n" "SYSTEM IS STABLE\n"
] ]
} }
] ],
},
{
"cell_type": "code",
"source": [ "source": [
"# Third Testing\n", "# Second Testing\n",
"den = input(\"Enter your polynomial: \")\n", "den = input(\"Enter your polynomial: \")\n",
"k_in = input(\"Enter your K: \")\n", "k_in = input(\"Enter your K: \")\n",
"\n", "\n",
"rs = RouthStability(den)\n", "rs = RouthStability(den)\n",
"rs.set_k(k_in)\n", "rs.set_k(k_in)\n",
"rs.calc_routh()" "rs.calc_routh()"
], ]
},
{
"cell_type": "code",
"execution_count": 137,
"metadata": { "metadata": {
"colab": { "colab": {
"base_uri": "https://localhost:8080/" "base_uri": "https://localhost:8080/"
@ -180,11 +164,10 @@
"id": "jaif_A4_hfeJ", "id": "jaif_A4_hfeJ",
"outputId": "0b387e7e-efbf-4f5c-fb45-d98489bbba3e" "outputId": "0b387e7e-efbf-4f5c-fb45-d98489bbba3e"
}, },
"execution_count": 137,
"outputs": [ "outputs": [
{ {
"output_type": "stream",
"name": "stdout", "name": "stdout",
"output_type": "stream",
"text": [ "text": [
"Enter your polynomial: 1.2 6.81 7.31\n", "Enter your polynomial: 1.2 6.81 7.31\n",
"Enter your K: 3.141\n", "Enter your K: 3.141\n",
@ -196,16 +179,31 @@
"SYSTEM IS STABLE\n" "SYSTEM IS STABLE\n"
] ]
} }
],
"source": [
"# Third Testing\n",
"den = input(\"Enter your polynomial: \")\n",
"k_in = input(\"Enter your K: \")\n",
"\n",
"rs = RouthStability(den)\n",
"rs.set_k(k_in)\n",
"rs.calc_routh()"
] ]
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "SjkQCR9chk6P"
},
"execution_count": null,
"outputs": []
} }
] ],
} "metadata": {
"colab": {
"collapsed_sections": [],
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}