def test_simple_integrator_constant(): # Setup simple integrator with constant input I = integrator.SimpleIntegrator() I.ubar = np.array([4.13,]) # Solution params tf = 10 x0 = 15.2 npts = 100 # Reference solution t_ref = np.linspace(0, tf, npts) x_ref = (x0 + t_ref * I.ubar).reshape((npts, 1)) sim = I.compute_trajectory(x0, tf=tf, n=npts) assert(np.allclose(t_ref, sim.t)) assert(np.allclose(x_ref, sim.x)) assert(np.allclose(x_ref, sim.y))
def test_simple_integrator_ramp(): """Simple integrator with ramp input""" I = integrator.SimpleIntegrator() # Solution params tf = 10 x0 = 39.4 npts = 100 # Ramp input ramp_cst = np.pi def u(t): return np.asarray(t * ramp_cst) # Reference solution t_ref = np.linspace(0, tf, npts) x_ref = (x0 + 0.5 * ramp_cst * t_ref**2).reshape((npts, 1)) sim = I.compute_trajectory(x0, tf=tf, n=npts, u=u) assert(np.allclose(t_ref, sim.t)) assert(np.allclose(x_ref, sim.x)) assert(np.allclose(x_ref, sim.y))
""" Created on Fri Nov 16 10:13:40 2018 @author: Alexandre """ ############################################################################### import numpy as np ############################################################################### from pyro.dynamic import integrator ################################### # Simple integrator ################################### si = integrator.SimpleIntegrator() si.ubar = np.array([1]) # constant input = 1 ################################### # Analysis ################################### # Phase plane si.plot_phase_plane(0, 0) # only one state for two axis! # Simulation si.compute_trajectory(np.array([2])) # Compute cost si.sim.compute_cost()