# Define the sizes of the state and the input x = sys.state(3) u = sys.input(1) # Define functions that can't be defined as functions above, i.e. # f(y,x_1,x_2,x_3,...,x_n) = g(y,x_1,x_2,x_3,...,x_n) # The method receive the name of the function, the f(y,x_1,x_2,...,x_n) # function, the g(y,x_1,x_2,...,x_n) function, and a list with tuples # representing the args that call the function (this is a hack, # because the actual matching system is not as good as i want). # State function sys.f(Matrix( [u[0]/A_1 -K_1 / A_1 * pow(x[0], 2.475), (K_1 / A_c) * pow(x[0], 2.475) - (K_c * b_c / A_c) * pow(x[1], 1.8), (K_c * b_c / A_2) * pow(x[1], 1.8) - (K_2 / A_2) * x[2] ]) ) # Output function sys.h(Matrix([x[2]])) # Linearization!!! A,B,C = sys.linearize(x, u) print "A =" print(A) print "B =" print(B)
# The method receive the name of the function, the f(y,x_1,x_2,...,x_n) # function, the g(y,x_1,x_2,...,x_n) function, and a list with tuples # representing the args that call the function (this is a hack, # because the actual matching system is not as good as i want). beta = sys.function( "beta", lambda y,x: l * sin(y) - 4*r, # f(y, x_1, x_2, x_3. ... , x_n) lambda y,x: 2 * x * cos(y), # g(y, x_1, x_2, x_3, ... , x_n) [(x[0],)] ) # State function sys.f(Matrix( [x[1], 9.81 - 2 * T(rho(L(beta(x[0])),x[2])) * sin(beta(x[0]))/M_p - k_f * x[1] / M_p, A * r * (rho_e * u[0] - rho(L(beta(x[0])),x[2]) * u[1] ) ]) ) # Output function sys.h(Matrix([x[0]])) # Linearization!!! A,B,C = sys.linearize(Matrix([0.5,0,0.01417]), Matrix([5, 5.7690])) print "A =" print(A) print "B =" print(B)