Created
April 7, 2020 22:18
-
-
Save brilliant-ember/eae69ace1797ab8c4b9d483e93a88472 to your computer and use it in GitHub Desktop.
Converts a control lib transfer function to sympy lib symbolic equation, uses x instead of s for the symbolic representation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tf_to_symbolic_fraction(tf): | |
x = symbols('x') | |
num, den = tfdata(tf) | |
num = num[0][0] | |
den = den[0][0] | |
counter = 1 | |
length_num = len(num) | |
length_den = len(den) | |
sym_num, sym_den = 0,0 | |
if(length_num == 0): | |
raise ValueError ("The fraction num should not be empty") | |
elif(length_den == 0 ): | |
raise ValueError("The fraction den should not be empty") | |
for i in range(length_num): | |
sym_num+=num[i]*(x**(length_num - counter)) | |
counter += counter | |
counter = 1 | |
for i in range(length_den): | |
sym_den+=den[i]*(x**(length_den - counter)) | |
counter += counter | |
return sym_num/sym_den |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
make sure to do the following imports: