示例#1
0
def test_dynamics_single_input():
    """Test dynamics equation with single input."""
    a = np.array([[1.0, 2.0], [0.0, 1.0]])
    b = np.array([[1.0], [3.0]])
    c = np.zeros((1, 2))

    s = StateSpace(a, b, c)

    assert np.all(s.dynamics([1.0, 1.0], [1.0]) == np.array([4.0, 4.0]))
示例#2
0
def test_output_mimo():
    """Test output equation with multiple inputs, multiple outputs."""
    a = np.zeros((2, 2))
    b = np.zeros((2, 2))
    c = np.eye(2)
    d = np.eye(2)

    s = StateSpace(a, b, c, d)

    assert np.all(s.output([1.0, 1.0], [2.0, 3.0]) == np.array([3.0, 4.0]))
示例#3
0
def test_output_miso():
    """Test output equation with multiple inputs, single output."""
    a = np.zeros((2, 2))
    b = np.zeros((2, 2))
    c = np.array([[1.0, 1.0]])
    d = np.array([[2.0, 3.0]])

    s = StateSpace(a, b, c, d)

    assert np.all(s.output([1.0, 1.0], [1.0, 1.0]) == np.array([7.0]))
示例#4
0
def test_output_siso():
    """Test output equation with single input, single output."""
    a = np.zeros((2, 2))
    b = np.zeros((2, 1))
    c = np.array([[1.0, 1.0]])
    d = np.array([[2.0]])

    s = StateSpace(a, b, c, d)

    assert s.output([1.0, 1.0], [1.0]) == np.array([4.0])
示例#5
0
def test_auto_feedthrough_matrix():
    """Test if a zero feedthrough matrix is created if none specified."""
    a = np.zeros((2, 2))
    b = np.zeros((2, 3))
    c = np.zeros((4, 2))

    s = StateSpace(a, b, c)
    assert s.d.shape == (4, 3)
示例#6
0
def test_invalid_output_matrix_dimensions():
    """Test exception if C and A have different number of columns."""
    a = np.zeros((2, 2))
    b = np.zeros((2, 1))
    c = np.zeros((1, 3))

    with pytest.raises(ValueError) as excinfo:
        StateSpace(a, b, c)
    assert "Invalid matrix dimensions" in str(excinfo.value)
示例#7
0
def test_invalid_state_matrix_dimensions():
    """Test exception if A is not square."""
    a = np.zeros((2, 1))
    b = np.zeros((2, 1))
    c = np.zeros((1, 2))

    with pytest.raises(ValueError) as excinfo:
        StateSpace(a, b, c)
    assert "Invalid matrix dimensions" in str(excinfo.value)
示例#8
0
def test_invalid_feedthrough_matrix_dimensions():
    """Test exception if D does not match to B and C."""
    a = np.zeros((2, 2))
    b = np.zeros((2, 3))
    c = np.zeros((4, 2))
    d = np.zeros((4, 2))

    with pytest.raises(ValueError) as excinfo:
        StateSpace(a, b, c, d)
    assert "Invalid matrix dimensions" in str(excinfo.value)
示例#9
0
def test_human_friendly_form():
    """Test the __str__() method of a StateSpace object."""
    a = np.array([[1.0, 2.0], [0.0, 1.0]])
    b = np.array([[1.0, 2.0], [3.0, 2.0]])
    c = np.zeros((1, 2))

    s = StateSpace(a, b, c)

    reference = \
        "LTI discrete-time system.\n\n" \
        "State matrix A:\n" \
        "[[ 1.  2.]\n" \
        " [ 0.  1.]]\n\n" \
        "Input matrix B:\n" \
        "[[ 1.  2.]\n" \
        " [ 3.  2.]]\n\n" \
        "Output matrix C:\n" \
        "[[ 0.  0.]]\n\n" \
        "Feedthrough matrix D:\n" \
        "[[ 0.  0.]]\n"

    assert s.__str__() == reference