Пример #1
0
 def test_02(self):
     t = np.array([0.0, 1.0, 1.0, 3.0])
     u = np.array([0.0, 0.0, 1.0, 1.0])
     # Simple integrator: x'(t) = u(t)
     system = ([1.0],[1.0,0.0])
     tout, y, x = lsim2(system, u, t, X0=[1.0])
     expected_x = np.maximum(1.0, tout)
     assert_almost_equal(x[:,0], expected_x)
Пример #2
0
 def test_03(self):
     t = np.array([0.0, 1.0, 1.0, 1.1, 1.1, 2.0])
     u = np.array([0.0, 0.0, 1.0, 1.0, 0.0, 0.0])
     # Simple integrator:  x'(t) = u(t)
     system = ([1.0],[1.0, 0.0])
     tout, y, x = lsim2(system, u, t, hmax=0.01)
     expected_x = np.array([0.0, 0.0, 0.0, 0.1, 0.1, 0.1])
     assert_almost_equal(x[:,0], expected_x)
Пример #3
0
 def test_03(self):
     t = np.array([0.0, 1.0, 1.0, 1.1, 1.1, 2.0])
     u = np.array([0.0, 0.0, 1.0, 1.0, 0.0, 0.0])
     # Simple integrator:  x'(t) = u(t)
     system = ([1.0], [1.0, 0.0])
     tout, y, x = lsim2(system, u, t, hmax=0.01)
     expected_x = np.array([0.0, 0.0, 0.0, 0.1, 0.1, 0.1])
     assert_almost_equal(x[:, 0], expected_x)
Пример #4
0
 def test_02(self):
     t = np.array([0.0, 1.0, 1.0, 3.0])
     u = np.array([0.0, 0.0, 1.0, 1.0])
     # Simple integrator: x'(t) = u(t)
     system = ([1.0], [1.0, 0.0])
     tout, y, x = lsim2(system, u, t, X0=[1.0])
     expected_x = np.maximum(1.0, tout)
     assert_almost_equal(x[:, 0], expected_x)
Пример #5
0
 def test_06(self):
     """Test use of the default values of the arguments `T` and `U`."""
     # Second order system with a repeated root: x''(t) + 2*x(t) + x(t) = 0.
     # With initial conditions x(0)=1.0 and x'(t)=0.0, the exact solution
     # is (1-t)*exp(-t).
     system = ([1.0], [1.0, 2.0, 1.0])
     tout, y, x = lsim2(system, X0=[1.0, 0.0])
     expected_x = (1.0 - tout) * np.exp(-tout)
     assert_almost_equal(x[:,0], expected_x)
Пример #6
0
 def test_01(self):
     t = np.linspace(0,10,1001)
     u = np.zeros_like(t)
     # First order system: x'(t) + x(t) = u(t), x(0) = 1.
     # Exact solution is x(t) = exp(-t).
     system = ([1.0],[1.0,1.0])
     tout, y, x = lsim2(system, u, t, X0=[1.0])
     expected_x = np.exp(-tout)
     assert_almost_equal(x[:,0], expected_x)
Пример #7
0
 def test_06(self):
     """Test use of the default values of the arguments `T` and `U`."""
     # Second order system with a repeated root: x''(t) + 2*x(t) + x(t) = 0.
     # With initial conditions x(0)=1.0 and x'(t)=0.0, the exact solution
     # is (1-t)*exp(-t).
     system = ([1.0], [1.0, 2.0, 1.0])
     tout, y, x = lsim2(system, X0=[1.0, 0.0])
     expected_x = (1.0 - tout) * np.exp(-tout)
     assert_almost_equal(x[:, 0], expected_x)
Пример #8
0
 def test_01(self):
     t = np.linspace(0, 10, 1001)
     u = np.zeros_like(t)
     # First order system: x'(t) + x(t) = u(t), x(0) = 1.
     # Exact solution is x(t) = exp(-t).
     system = ([1.0], [1.0, 1.0])
     tout, y, x = lsim2(system, u, t, X0=[1.0])
     expected_x = np.exp(-tout)
     assert_almost_equal(x[:, 0], expected_x)
Пример #9
0
 def test_04(self):
     t = np.linspace(0, 10, 1001)
     u = np.zeros_like(t)
     # Second order system with a repeated root: x''(t) + 2*x(t) + x(t) = 0.
     # With initial conditions x(0)=1.0 and x'(t)=0.0, the exact solution
     # is (1-t)*exp(-t).
     system = ([1.0], [1.0, 2.0, 1.0])
     tout, y, x = lsim2(system, u, t, X0=[1.0, 0.0])
     expected_x = (1.0 - tout) * np.exp(-tout)
     assert_almost_equal(x[:,0], expected_x)
Пример #10
0
 def test_04(self):
     t = np.linspace(0, 10, 1001)
     u = np.zeros_like(t)
     # Second order system with a repeated root: x''(t) + 2*x(t) + x(t) = 0.
     # With initial conditions x(0)=1.0 and x'(t)=0.0, the exact solution
     # is (1-t)*exp(-t).
     system = ([1.0], [1.0, 2.0, 1.0])
     tout, y, x = lsim2(system, u, t, X0=[1.0, 0.0])
     expected_x = (1.0 - tout) * np.exp(-tout)
     assert_almost_equal(x[:, 0], expected_x)
Пример #11
0
    def test_07(self):
        """Test the simulation of a MIMO system"""
        # Basic MIMO system. Two inputs, two outputs. Output same as input.
        A = np.zeros((1, 1))
        B = np.zeros((1, 2))
        C = np.zeros((2, 1))
        D = np.eye(2)

        t = np.arange(3)
        u0 = np.arange(3)
        u1 = 2 * u0
        u = np.vstack((u0, u1)).T
        tout, y, x = lsim2((A, B, C, D), T=t, U=u)
        expected_y = u
        expected_x = np.zeros((3, 1))
        assert_almost_equal(y, expected_y)
        assert_almost_equal(x, expected_x)
Пример #12
0
    def test_05(self):
        # This test triggers a "BadCoefficients" warning from scipy.signal.filter_design,
        # but the test passes.  I think the warning is related to the incomplete handling
        # of multi-input systems in scipy.signal.

        # A system with two state variables, two inputs, and one output.
        A = np.array([[-1.0, 0.0], [0.0, -2.0]])
        B = np.array([[1.0, 0.0], [0.0, 1.0]])
        C = np.array([1.0, 0.0])
        D = np.zeros((1,2))

        t = np.linspace(0, 10.0, 101)
        tout, y, x = lsim2((A,B,C,D), T=t, X0=[1.0, 1.0])
        expected_y = np.exp(-tout)
        expected_x0 = np.exp(-tout)
        expected_x1 = np.exp(-2.0*tout)
        assert_almost_equal(y, expected_y)
        assert_almost_equal(x[:,0], expected_x0)
        assert_almost_equal(x[:,1], expected_x1)
Пример #13
0
    def test_05(self):
        # This test triggers a "BadCoefficients" warning from scipy.signal.filter_design,
        # but the test passes.  I think the warning is related to the incomplete handling
        # of multi-input systems in scipy.signal.

        # A system with two state variables, two inputs, and one output.
        A = np.array([[-1.0, 0.0], [0.0, -2.0]])
        B = np.array([[1.0, 0.0], [0.0, 1.0]])
        C = np.array([1.0, 0.0])
        D = np.zeros((1, 2))

        t = np.linspace(0, 10.0, 101)
        tout, y, x = lsim2((A, B, C, D), T=t, X0=[1.0, 1.0])
        expected_y = np.exp(-tout)
        expected_x0 = np.exp(-tout)
        expected_x1 = np.exp(-2.0 * tout)
        assert_almost_equal(y, expected_y)
        assert_almost_equal(x[:, 0], expected_x0)
        assert_almost_equal(x[:, 1], expected_x1)