Skip to content

fix(timeresp): avoid warning for discrete -1 poles#1225

Closed
marko1olo wants to merge 1 commit into
python-control:mainfrom
marko1olo:fix-impulse-negative-pole-warning
Closed

fix(timeresp): avoid warning for discrete -1 poles#1225
marko1olo wants to merge 1 commit into
python-control:mainfrom
marko1olo:fix-impulse-negative-pole-warning

Conversation

@marko1olo

Copy link
Copy Markdown
Contributor

Fixes #1204.

_ideal_tfinal_and_dt() already treats negative real discrete poles separately, but a pole exactly on the unit circle at -1 was still sent through the decaying negative-real path. That path divides by real(log(pole)), which is zero for -1, so impulse_response() emitted a RuntimeWarning even though the response itself was valid.

This change keeps decaying negative real poles such as -0.5 on the existing decay-based path, keeps positive real discrete poles on the existing padded path, and lets unit-circle negative real poles flow to the pure oscillatory-mode estimate.

Verification:

  • Reproduced the issue script with warnings.simplefilter("error", RuntimeWarning) before the fix.
  • python -m pytest control\tests\timeresp_test.py::TestTimeresp::test_auto_generated_time_vector_tfinal control\tests\timeresp_test.py::TestTimeresp::test_discrete_negative_real_pole_tfinal control\tests\timeresp_test.py::TestTimeresp::test_discrete_time_impulse_negative_poles_no_warning -q
  • python -m pytest control\tests\timeresp_test.py -q
  • python -m ruff check --no-cache control\timeresp.py control\tests\timeresp_test.py
  • PYTHONPYCACHEPREFIX=C:\tmp\pycache-python-control-1204 python -m compileall -q control\timeresp.py control\tests\timeresp_test.py
  • git diff --check

AI-assisted contribution: implemented with OpenAI Codex and manually verified with the commands above.

Treat negative real discrete poles on the unit circle as oscillatory modes instead of decaying negative real modes, avoiding a divide-by-zero RuntimeWarning when computing the default impulse-response horizon.

Co-authored-by: OpenAI Codex <codex@openai.com>
@slivingston

Copy link
Copy Markdown
Member

@marko1olo There is already an open PR that is supposed to fix #1204 : #1216

I will re-open this PR if the other one is not sufficient.

@slivingston slivingston closed this Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RuntimeWarning in impulse_response for discrete-time systems with negative real poles

2 participants