예제 #1
0
def test_pole_zero():
    if not matplotlib:
        skip("Matplotlib not the default backend")

    assert _to_tuple(*pole_zero_numerical_data(tf1)) == \
        ((), ((-0.24999999999999994+1.3919410907075054j), (-0.24999999999999994-1.3919410907075054j)))
    assert _to_tuple(*pole_zero_numerical_data(tf2)) == \
        ((0.0,), ((-0.25+0.3227486121839514j), (-0.25-0.3227486121839514j)))
    assert _to_tuple(*pole_zero_numerical_data(tf3)) == \
        ((0.0,), ((-0.5000000000000004+0.8660254037844395j),
        (-0.5000000000000004-0.8660254037844395j), (0.9999999999999998+0j)))
    assert _to_tuple(*pole_zero_numerical_data(tf7)) == \
        (((-0.6722222222222222+0.8776898690157247j), (-0.6722222222222222-0.8776898690157247j)),
        ((2.220446049250313e-16+1.2797182176061541j), (2.220446049250313e-16-1.2797182176061541j),
        (-0.7657146670186428+0.5744385024099056j), (-0.7657146670186428-0.5744385024099056j),
        (0.7657146670186427+0.5744385024099052j), (0.7657146670186427-0.5744385024099052j)))
    assert _to_tuple(*pole_zero_numerical_data(ser1)) == \
        ((), (5.0, 0.0, 0.0, 0.0))
    assert _to_tuple(*pole_zero_numerical_data(par1)) == \
        ((-5.645751311064592, -0.5000000000000008, -0.3542486889354093),
        ((-0.24999999999999986+1.3919410907075052j),
        (-0.24999999999999986-1.3919410907075052j), (-0.2499999999999998+0.32274861218395134j),
        (-0.2499999999999998-0.32274861218395134j)))
    assert _to_tuple(*pole_zero_numerical_data(tf8)) == \
        ((),
         ((-1.1641600331447917-3.545808351896439j),
          (-0.8358399668552097+2.5458083518964383j)))
예제 #2
0
def test_errors():
    if not matplotlib:
        skip("Matplotlib not the default backend")

    # Invalid `system` check
    tfm = TransferFunctionMatrix([[tf6, tf5], [tf5, tf6]])
    expr = 1 / (s**2 - 1)
    raises(NotImplementedError, lambda: pole_zero_plot(tfm))
    raises(NotImplementedError, lambda: pole_zero_numerical_data(expr))
    raises(NotImplementedError, lambda: impulse_response_plot(expr))
    raises(NotImplementedError, lambda: impulse_response_numerical_data(tfm))
    raises(NotImplementedError, lambda: step_response_plot(tfm))
    raises(NotImplementedError, lambda: step_response_numerical_data(expr))
    raises(NotImplementedError, lambda: ramp_response_plot(expr))
    raises(NotImplementedError, lambda: ramp_response_numerical_data(tfm))
    raises(NotImplementedError, lambda: bode_plot(tfm))

    # More than 1 variables
    tf_a = TransferFunction(a, s + 1, s)
    raises(ValueError, lambda: pole_zero_plot(tf_a))
    raises(ValueError, lambda: pole_zero_numerical_data(tf_a))
    raises(ValueError, lambda: impulse_response_plot(tf_a))
    raises(ValueError, lambda: impulse_response_numerical_data(tf_a))
    raises(ValueError, lambda: step_response_plot(tf_a))
    raises(ValueError, lambda: step_response_numerical_data(tf_a))
    raises(ValueError, lambda: ramp_response_plot(tf_a))
    raises(ValueError, lambda: ramp_response_numerical_data(tf_a))
    raises(ValueError, lambda: bode_plot(tf_a))

    # lower_limit > 0 for response plots
    raises(ValueError, lambda: impulse_response_plot(tf1, lower_limit=-1))
    raises(ValueError, lambda: step_response_plot(tf1, lower_limit=-0.1))
    raises(ValueError, lambda: ramp_response_plot(tf1, lower_limit=-4 / 3))

    # slope in ramp_response_plot() is negative
    raises(ValueError, lambda: ramp_response_plot(tf1, slope=-0.1))

    # incorrect frequency or phase unit
    raises(ValueError, lambda: bode_plot(tf1, freq_unit='hz'))
    raises(ValueError, lambda: bode_plot(tf1, phase_unit='degree'))