<jupyter_start><jupyter_text>Recordatorio vectores<jupyter_code>a =[ [1,2],[3,4],[5,6] ]
a[1] #a[k]
a,b = [1,2]
x_ = [np.array ( np.array([1,2]) ) ,np.array([3,4])] 
x_
x_[0],x_[0].shape<jupyter_output><empty_output><jupyter_text>Manteniendo un estandar todos los vectores seran (n,1)<jupyter_code>g = np.zeros_like([1,2,3])[:,np.newaxis]
g.shape
x_[0][:,np.newaxis]
x_[0][:,np.newaxis].shape
x_[0].reshape(-1,1).shape<jupyter_output><empty_output><jupyter_text>Todos los vectores en columnaVer https://www.codecogs.com/latex/eqneditor.php$$x =\begin{bmatrix}x_1 \\ \vdots \\ x_n \\ \end{bmatrix}$$  Modelo de motor DC ![image.png](attachment:image.png)<jupyter_code>class Mundo(object):
    T = 0.01

    def __init__(self):
        self.t = [0]
        self.k = 0
        
    def simular(self):
        self.t.append( self.t[self.k] + self.T)
        self.k +=1
    
    def muestra(self):
        print(f"clase Mundo k:{self.k}, t: {self.t}")

class Sistema(Mundo):
    
    def __init__(self,x0):
        super().__init__()
        # x_ tendra: ej [ [x_10,x_20],[x_11,x_21],...,[x_1k,x_2k] ]
        self.x_ = [ np.array (x0).reshape(-1,1) ] 
        
        self.R = 1.26
        self.Kb = 0.0232
        self.L = 0.66
        self.J = 0.001
        self.Kt = 0.0232
        self.b = 0.001                
        self.parms = [self.R,self.Kb,self.L,self.J,self.Kt,self.b]
        self.Gamma = 0
        
        
        tmp_fx0,tmp_gx0 = self.MotorDC(u=0)
        self.f_ = [tmp_fx0]
        self.g_ = [tmp_gx0]
        

        
    @property
    def x(self):
        return self.x_[self.k].reshape(-1,1)
    
    @x.setter
    def xk1(self,val):
        self.x_.append( np.array (val) )

#Para sistemas afines de la forma \dot{x} = f(x) + g(x)u
    @property 
    def f(self):
        return self.f_[self.k].reshape(-1,1)
    @f.setter
    def f(self,val):
        self.f_.append( np.array(val) )
        
    @property 
    def g(self):
        return self.g_[self.k].reshape(-1,1)
    @g.setter
    def g(self,val):
        self.g_.append( np.array(val) )

        
    def MotorDC(self,u):
        #Solo esta parte de codigo se modifica para el sistema
        
        R,Kb,L,J,Kt,b = self.parms
        T = self.T
        
        tmp_f = np.array([ [-b / J,  Kt / J],
                           [-Kb / L,  -R / L]])       
        f = self.x + self.T * tmp_f @ self.x        
        
        g = T*np.array([ 0, 1 / L])
        return f,g
        

    def simular(self,u):        
        self.f,self.g = self.MotorDC(u)        
        #Añadimos ruido
        #print(self.x.shape,self.f.shape,self.g.shape)
        
        self.xk1 = self.f + self.g*u + self.Gamma
        super().simular()
        
    def muestra(self):
        print(f"clase Sistema x: {self.x}, x_:{self.x_} ")
        super().muestra()
        
        
    def plot(self,op=0):
        x0 = [i[0] for i in self.x_]
        x1 = [i[1] for i in self.x_]
        
        if op == 0:
            plt.plot(self.t,x0)
            plt.plot(self.t,x1)
            plt.xlabel('t')
            plt.ylabel('X edos')
            plt.legend( ['x0','x1'] )
        if op == 1:
            plt.plot(self.t,x0)
            plt.xlabel('t')
            plt.ylabel('X edos')
            plt.legend( ['x0'] )<jupyter_output><empty_output><jupyter_text>Modelo de sistema autonomo sin entrada de control<jupyter_code>s1 = Sistema([.5,0])
s2 = Sistema([5,0])
u=0
for k in range(0,1000):
    s1.simular(u)
    s2.simular(u)

s1.plot(op=0)
s1.plot(op=1)
s1.plot(op=0)
s2.plot(op=0)
#[i[0] for i in s1.x_]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16976421636615813, 'fraction_numerical': 0.03384188626907073, 'mean_word_length': 1.8460931333859512, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '211649', 'license': 'MIT', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1508, 'n_words': 254, 'path': 'Sistema/Sistema_SinControl_Clase_Bien.ipynb', 'repo_name': 'IntroCursos/Mis_Ejemplos_Basicos', 'size': '3605'}