Skip to content

Commit 7d5019e

Browse files
UbeenIIslivingston
authored andcommitted
Fix negative real handling for tfinal of discrete-time systems
Squash-merge of #1216 Fixes #1204
1 parent 17baf62 commit 7d5019e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

control/tests/timeresp_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from copy import copy
44
from math import isclose
5+
import warnings
56

67
import numpy as np
78
import pytest
@@ -827,6 +828,14 @@ def test_auto_generated_time_vector_tfinal(self, tfsys, tfinal):
827828
T = _default_time_vector(tfsys)
828829
np.testing.assert_allclose(T[-1], tfinal, atol=0.5*ideal_dt)
829830

831+
def test_discrete_time_negative_one_settling(self):
832+
#system with -1 pole
833+
TF = TransferFunction([1,3,0],[1,3,2], dt=True)
834+
with warnings.catch_warnings():
835+
warnings.simplefilter("error")
836+
impulse_response(TF)
837+
838+
830839
@pytest.mark.parametrize("wn, zeta", [(10, 0), (100, 0), (100, .1)])
831840
def test_auto_generated_time_vector_dt_cont1(self, wn, zeta):
832841
"""Confirm a TF with a natural frequency of wn rad/s gets a

control/timeresp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,7 @@ def _ideal_tfinal_and_dt(sys, is_step=True):
21722172
m_z = np.abs(p) < sqrt_eps
21732173
p = p[~m_z]
21742174
# Negative reals- treated as oscillatory mode
2175-
m_nr = (p.real < 0) & (np.abs(p.imag) < sqrt_eps)
2175+
m_nr = (p.real < 0) & (np.abs(p.imag) < sqrt_eps) & (np.abs(p.real+1) > sqrt_eps)
21762176
p_nr, p = p[m_nr], p[~m_nr]
21772177
if p_nr.size > 0:
21782178
t_emp = np.max(log_decay_percent / np.abs((np.log(p_nr)/dt).real))

0 commit comments

Comments
 (0)