Skip to content

Instantly share code, notes, and snippets.

@Dephilia
Created September 24, 2019 07:36
Show Gist options
  • Save Dephilia/bd1488551bf0364c231a2460f9868a0b to your computer and use it in GitHub Desktop.
Save Dephilia/bd1488551bf0364c231a2460f9868a0b to your computer and use it in GitHub Desktop.
Jury's Test For Descrete Control System
"""
Title: Jury's Test For Descrete Control System
Copyright: Dephilia
Date: 2019/09/23
"""
def calnextrow(row):
"""This will cal a new row for test."""
# input: an an-1...
# ouput: bn bn-1...
size=len(row)
nextrow=[]
row_rev=row[::-1]
for i in range(size-1):
temp=row[0]*row_rev[i+1]-row[i+1]*row_rev[0]
nextrow.append(temp)
return nextrow
def main():
# Jury's test
"""
Input example:
[1,0,-0.25]
"""
import ast
intext=input("Input characteristic equation as array:\nFor example:[1,0,-0.25]\n")
testlist=ast.literal_eval(intext)
order=len(testlist)-1
# a_n>0
if testlist[0]<0:
print("a_n must large than 0.")
return 0
# First check Q(1)>0
r1=sum(testlist)
print("Q(1)=",r1)
if r1<=0:
print("Unstable")
return 0
# Next check (-1)^nQ(-1)>0
r2=(-1)**order*sum([testlist[i]*((-1)**(order-i)) for i in range(order)]+[testlist[-1]])
print("(-1)^n Q(-1)=",r2)
if r2<=0:
print("Unstable")
return 0
# Check |a0|<an
r3=abs(testlist[-1])<testlist[0]
print("|a0|<an=",r3)
if not r3:
print("Unstable")
return 0
# Establish Table
deal=testlist
print(0," - ",deal)
print(0," - ",deal[::-1])
for i in range(order-1):
deal=calnextrow(deal)
print(i+1," - ",deal)
print(i+1," - ",deal[::-1])
if abs(deal[0])>=abs(deal[-1]):
print("Unstable")
return 0
print("\033[1;35m Stable \033[0m")
if __name__=="__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment