Skip to content

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

@miroslavfikar

Description

@miroslavfikar

Description

When computing impulse responses for discrete-time systems with negative real poles, ct.impulse_response() generates a RuntimeWarning: divide by zero encountered in divide. This occurs even though the system is valid and the results are correct.

Minimal Reproducible Example

import control as ct
import numpy as np

# Discrete-time system with poles at -1 and -2
b, a = [1, 3, 0], [1, 3, 2]
sys = ct.TransferFunction(b, a, dt=True)

# This triggers the warning
t, y = ct.impulse_response(sys, 5)

Output:

RuntimeWarning: divide by zero encountered in divide
  t_emp = np.max(log_decay_percent / np.abs((np.log(p_nr)/dt).real))

Root Cause

The warning originates from the settling time calculation in the time response functions. For negative real poles in discrete-time systems:

  • np.log(-1) = 0 + πj (real part is exactly 0)
  • np.log(-2) = 0.693 + πj (real part is small)

The code attempts to compute settling time using:

t_emp = np.max(log_decay_percent / np.abs((np.log(p_nr)/dt).real))

When the real part of log(p_nr) is zero or near-zero, this causes division by zero.

For discrete-time systems, stability and settling behavior should be based on pole magnitudes (|pole| < 1), not logarithms of negative numbers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions