@@ -364,3 +364,73 @@ def test_phase_wrap(TF, wrap_phase, min_phase, max_phase):
364364 mag , phase , omega = ctrl .bode (TF , wrap_phase = wrap_phase )
365365 assert (min (phase ) >= min_phase )
366366 assert (max (phase ) <= max_phase )
367+
368+
369+ def test_freqresp_warn_infinite ():
370+ """Test evaluation of transfer functions at the origin"""
371+ sys_finite = ctrl .tf ([1 ], [1 , 0.01 ])
372+ sys_infinite = ctrl .tf ([1 ], [1 , 0.01 , 0 ])
373+
374+ # Transfer function with finite zero frequency gain
375+ np .testing .assert_almost_equal (sys_finite (0 ), 100 )
376+ np .testing .assert_almost_equal (sys_finite (0 , warn_infinite = False ), 100 )
377+ np .testing .assert_almost_equal (sys_finite (0 , warn_infinite = True ), 100 )
378+
379+ # Transfer function with infinite zero frequency gain
380+ with pytest .warns (RuntimeWarning , match = "divide by zero" ):
381+ np .testing .assert_almost_equal (sys_infinite (0 ), np .inf )
382+ with pytest .warns (RuntimeWarning , match = "divide by zero" ):
383+ np .testing .assert_almost_equal (
384+ sys_infinite (0 , warn_infinite = True ), np .inf )
385+ np .testing .assert_almost_equal (sys_infinite (0 , warn_infinite = False ), np .inf )
386+
387+ # Switch to state space
388+ sys_finite = ctrl .tf2ss (sys_finite )
389+ sys_infinite = ctrl .tf2ss (sys_infinite )
390+
391+ # State space system with finite zero frequency gain
392+ np .testing .assert_almost_equal (sys_finite (0 ), 100 )
393+ np .testing .assert_almost_equal (sys_finite (0 , warn_infinite = False ), 100 )
394+ np .testing .assert_almost_equal (sys_finite (0 , warn_infinite = True ), 100 )
395+
396+ # State space system with infinite zero frequency gain
397+ with pytest .warns (RuntimeWarning , match = "not finite" ):
398+ np .testing .assert_almost_equal (sys_infinite (0 ), np .inf )
399+ with pytest .warns (RuntimeWarning , match = "not finite" ):
400+ np .testing .assert_almost_equal (sys_infinite (0 ), np .inf )
401+ np .testing .assert_almost_equal (sys_infinite (0 , warn_infinite = True ), np .inf )
402+ np .testing .assert_almost_equal (sys_infinite (0 , warn_infinite = False ), np .inf )
403+
404+
405+ def test_dcgain_consistency ():
406+ """Test to make sure that DC gain is consistently evaluated"""
407+ # Set up transfer function with pole at the origin
408+ sys_tf = ctrl .tf ([1 ], [1 , 0 ])
409+ assert 0 in sys_tf .pole ()
410+
411+ # Set up state space system with pole at the origin
412+ sys_ss = ctrl .tf2ss (sys_tf )
413+ assert 0 in sys_ss .pole ()
414+
415+ # Evaluation
416+ np .testing .assert_equal (sys_tf (0 ), np .inf + 0j )
417+ np .testing .assert_equal (sys_ss (0 ), np .inf + 0j )
418+ np .testing .assert_equal (sys_tf .dcgain (), np .inf + 0j )
419+ np .testing .assert_equal (sys_ss .dcgain (), np .inf + 0j )
420+
421+ # Set up transfer function with pole, zero at the origin
422+ sys_tf = ctrl .tf ([1 , 0 ], [1 , 0 ])
423+ assert 0 in sys_tf .pole ()
424+ assert 0 in sys_tf .zero ()
425+
426+ sys_ss = ctrl .tf2ss (ctrl .tf ([1 , 0 ], [1 , 1 ])) * \
427+ ctrl .tf2ss (ctrl .tf ([1 ], [1 , 0 ]))
428+ assert 0 in sys_ss .pole ()
429+ assert 0 in sys_ss .zero ()
430+
431+ # Pole and zero at the origin should give nan for the response
432+ np .testing .assert_equal (sys_tf (0 ), np .nan )
433+ np .testing .assert_equal (sys_tf .dcgain (), np .nan )
434+ # TODO: state space cases not yet working
435+ # np.testing.assert_equal(sys_ss(0), np.nan)
436+ # np.testing.assert_equal(sys_ss.dcgain(), np.nan)
0 commit comments