#Problem 4  
#http://apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations

import numpy as np 
from scipy.integrate import odeint 
import matplotlib.pyplot as plt 

def model(z,t):
    if (t > 5):
        u = 2
    else:
        u = 0    
    x = z[0]
    y = z[1]
    dxdt = (- x + u ) / 2
    dydt = (- y + x) / 5
    dzdt = [dxdt,dydt]
    return dzdt

#initial conditions 
z0=[0,0]
t = np.linspace(0,40,201)

#Solve ode 
z = odeint(model,z0,t)

print(z)

#Step response
us = np.zeros(201) 
us[26:] = 2
ts = np.linspace(0,40,201)

#plot graph 


plt.plot(t,z[:,0],linewidth = 1, label = "dxdt")
plt.plot(t,z[:,1],'b-', label = "dydt")
plt.plot(ts,us,'r--', label = "Step")
plt.xlabel("Time")
plt.ylabel("y(t)")
plt.legend()
plt.show()


c9a7ab5c073c96afa633ee5259baaf1f4e2098c1
<mask token>


def model(z, t):
    if t > 5:
        u = 2
    else:
        u = 0
    x = z[0]
    y = z[1]
    dxdt = (-x + u) / 2
    dydt = (-y + x) / 5
    dzdt = [dxdt, dydt]
    return dzdt


<mask token>

<mask token>


def model(z, t):
    if t > 5:
        u = 2
    else:
        u = 0
    x = z[0]
    y = z[1]
    dxdt = (-x + u) / 2
    dydt = (-y + x) / 5
    dzdt = [dxdt, dydt]
    return dzdt


<mask token>
print(z)
<mask token>
plt.plot(t, z[:, 0], linewidth=1, label='dxdt')
plt.plot(t, z[:, 1], 'b-', label='dydt')
plt.plot(ts, us, 'r--', label='Step')
plt.xlabel('Time')
plt.ylabel('y(t)')
plt.legend()
plt.show()

<mask token>


def model(z, t):
    if t > 5:
        u = 2
    else:
        u = 0
    x = z[0]
    y = z[1]
    dxdt = (-x + u) / 2
    dydt = (-y + x) / 5
    dzdt = [dxdt, dydt]
    return dzdt


z0 = [0, 0]
t = np.linspace(0, 40, 201)
z = odeint(model, z0, t)
print(z)
us = np.zeros(201)
us[26:] = 2
ts = np.linspace(0, 40, 201)
plt.plot(t, z[:, 0], linewidth=1, label='dxdt')
plt.plot(t, z[:, 1], 'b-', label='dydt')
plt.plot(ts, us, 'r--', label='Step')
plt.xlabel('Time')
plt.ylabel('y(t)')
plt.legend()
plt.show()

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt


def model(z, t):
    if t > 5:
        u = 2
    else:
        u = 0
    x = z[0]
    y = z[1]
    dxdt = (-x + u) / 2
    dydt = (-y + x) / 5
    dzdt = [dxdt, dydt]
    return dzdt


z0 = [0, 0]
t = np.linspace(0, 40, 201)
z = odeint(model, z0, t)
print(z)
us = np.zeros(201)
us[26:] = 2
ts = np.linspace(0, 40, 201)
plt.plot(t, z[:, 0], linewidth=1, label='dxdt')
plt.plot(t, z[:, 1], 'b-', label='dydt')
plt.plot(ts, us, 'r--', label='Step')
plt.xlabel('Time')
plt.ylabel('y(t)')
plt.legend()
plt.show()

#Problem 4  
#http://apmonitor.com/pdc/index.php/Main/SolveDifferentialEquations

import numpy as np 
from scipy.integrate import odeint 
import matplotlib.pyplot as plt 

def model(z,t):
    if (t > 5):
        u = 2
    else:
        u = 0    
    x = z[0]
    y = z[1]
    dxdt = (- x + u ) / 2
    dydt = (- y + x) / 5
    dzdt = [dxdt,dydt]
    return dzdt

#initial conditions 
z0=[0,0]
t = np.linspace(0,40,201)

#Solve ode 
z = odeint(model,z0,t)

print(z)

#Step response
us = np.zeros(201) 
us[26:] = 2
ts = np.linspace(0,40,201)

#plot graph 


plt.plot(t,z[:,0],linewidth = 1, label = "dxdt")
plt.plot(t,z[:,1],'b-', label = "dydt")
plt.plot(ts,us,'r--', label = "Step")
plt.xlabel("Time")
plt.ylabel("y(t)")
plt.legend()
plt.show()

