def __init__(self,num_dict,den_dict,var_dict,opt_dict='all',myvar='s'): ''' Class to represent a model of a linear time invariant dynamical system. Parameters ---------- opt_dict : dictionary Represent the parameters of `num_dict` and `den_dict` that can be optimized and their initial values. {'A':10,'p':10} var_dict : dictionary Represents all parameters of `num` and `den`. {'A':10,'p':10} num_dict : dictionary Represents numerator. Keys are the power of the polynomial variable and values are a string of the symbolic form of the coefficient. {'0':'A*p'} den_dict : dictionary Represents denominator. Similar to `num_dict`. {'1':'1','0':p} input : array Input to the system. ''' if type(num_dict) == type({}): self.num_dict = num_dict self.num_str = poly_dict_to_str(self.num_dict,myvar=myvar) elif type(num_dict) == type(''): self.num_str = num_dict self.num_dict = PolyHasher(num_dict,var_dict,myvar=myvar)[1] if type(den_dict) == type({}): self.den_dict = den_dict self.den_str = poly_dict_to_str(self.den_dict,myvar=myvar) elif type(den_dict) == type(''): self.den_str = den_dict self.den_dict = PolyHasher(den_dict,var_dict,myvar=myvar)[1] self.var_dict = var_dict if opt_dict == False: self.opt_dict = opt_dict elif opt_dict == 'all': self.opt_dict = self.var_dict.copy() elif isinstance(opt_dict,dict): self.opt_dict = opt_dict num = exec_coeffs(self.num_dict,var_dict) den = exec_coeffs(self.den_dict,var_dict) TransferFunction.__init__(self,num,den)
reload(systemid) from systemid import Model,fit_time from systemid.data import time_data del systemid from controls import TransferFunction,create_step_vector from numpy import arange # theorectical system parameters wn = 10.0*2*pi z = .7 g = 2.0 num = [g*wn**2] den = [1,2*z*wn,wn**2] # create some data tf = TransferFunction(num,den) t = arange(0,2,.01) u = create_step_vector(t, step_time=.5, amp=1.0) y = tf.lsim(u,t) ################################################# # start systemid num_dict = {'0':'g*wn**2'} den_dict = {'2':'1','1':'2*z*wn','0':'wn**2'} var_dict = {'g':1,'z':z,'wn':10} to_opt_dict = {'g':5,'z':z,'wn':10} data = time_data(t,u,y) ###############################
def __repr__(self, labelstr='systemid.Model'): return TransferFunction.__repr__(self,labelstr)