Skip to content

bug: delayed dirac input not considered in forced_response #1152

Description

@BobAubouin

Hi,

I have encountered a strange issue using the function forced_response with a NonlinearIOSystem object:

When applying a dirac as input, if the dirac is applied after too much time after the beginning of the simulation, the response of the system does not include its impact.
Here is a small piece of code to reproduce the issue:

import numpy as np
import matplotlib.pyplot as plt
import control

def dynamic_function(t, x, u, param=None):
    """
    Dynamic function for the system.
    """
    A = np.array([[0, 1], [-1, -1]])
    B = np.array([[0], [1]])
    return A @ x + B @ u

def output_function(t, x, u, param=None):
    """
    Output function for the system.
    """
    C = np.array([[1, 0]])
    return C @ x

sys = control.NonlinearIOSystem(
    dynamic_function, output_function,
    inputs=1,
    outputs=1,
    states=2
    )

t = np.linspace(0, 10, 100)
u = np.zeros_like(t)


dirac_index = 6


u[dirac_index] = 1  # Dirac input at t=0

results = control.forced_response(sys, T=t, U=u)

plt.figure()
plt.plot(t, results.y[0], label='Output')
plt.title('Response of Nonlinear System to Dirac Input')
plt.xlabel('Time (s)')
plt.ylabel('Output')
plt.grid()
plt.legend()
plt.show()

If dirac_index is inferior or equal to 5, the normal output is obtained while if dirac_index is superior to 6, both the output and the state of the function are null for the whole simulation time.

Here are the installed package:
├── control v0.10.1
│ ├── matplotlib v3.10.3
│ ├── numpy v2.2.5
│ └── scipy v1.15.3

Using python 3.12.3.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions