-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
forced_response giving different output depending on Python and/or numpy version #993
Comments
I installed NumPy 1.20.3 and reproduced the same plot as above for Setup 1 (Python 3.8, numpy 1.20.3, control 0.9.4). As such, I cannot reproduce the different behavior that you described. Can you try to run your code on Google Colab or with Binder as described at https://github.com/python-control/python-control?tab=readme-ov-file#have-a-go-now ? |
Did you install it following the instructions at https://python-control.readthedocs.io/en/0.10.0/intro.html#installation? In particular, with Anaconda, you should be able to
|
As for Binder, go to https://mybinder.org/v2/gh/python-control/python-control/HEAD and then create a Python 3 Notebook; the correct icon is highlighted in red here: In the first space, enter Run it to install |
Yes, I was using the conda comand to intstall the control systems library, as described in the installation section, and as pointed out in your response. |
Hi guys. I'm also facing issues with the To reproduce my setup here are the versions: MWE: import matplotlib.pyplot as plt
import numpy as np
import control
from math import pi, sin, cos
wi = 2*pi*1.2 # input *angular frequency
Ai = 0.679 # input amplitude
Mr = 2.718 # actual mass
Kd = 400.0 # impedance stiffness
Dd = 2*sqrt(Kd) # impedance damping
input_period = 2 * pi / wi
time = np.linspace(0, 2.0*input_period, 600)
x_ref_time = Ai * np.sin(wi * time)
s = control.tf('s')
Z = Dd*s + Kd # s-domain impedance
ref_to_error_tf = (Mr * s**2)/(Z + Mr * s**2)
error_response = control.forced_response(ref_to_error_tf, time, x_ref_time, transpose=True)
plt.plot(error_response.t, error_response.x[0]) The I'll reproduce the execution of this code snippet on my Ubuntu 22.04 soon. |
I took a look at the above issue. I note that in all cases there is some type of access to the state of the underlying realization of the transfer function. In particular, in the original post the initial condition for the state is set and in the latest post the value of the first state is plotted. This is a potential problem because the state space realization for a transfer function is non-unique and can depend on how the conversion to state space is done. In the current release of python-control, this is done in one of two ways:
Using the Note that when you specify the initial condition, you get a warning that something funny may happen:
This is a hint that something funny may be happening. With that as background, I took the original example that was posted and ran in Python 3.12 with slycot installed. I converted the transfer function to state space form using We see that the initial output differs, because the state space representations are different and so setting I suspect this also explains the second example, where the internal state |
I have tested the following code on three different setups.
`import matplotlib.pyplot as plt
import control as ct
import numpy as np
num = [2,4]
den = [1,2,4]
W = ct.tf(num,den)
timeVector = np.linspace(0,10,200)
inputVector = np.sin(2*timeVector) + np.ones(timeVector.shape)
x0 = np.array([[-0.4],[0.1]])
timeReturned, systemOutput = ct.forced_response(W,timeVector,inputVector,x0)`
Setup 1: Python 3.8, numpy 1.20.3, control 0.9.4
Setup 2: Python 3.11, numpy 1.26.4, control 0.9.4
Setup 3: Python 3.11, numpy 1.26.4, control 0.10.0
Setup 1 gives a different output than setup 2 and 3. The first value of the output of setup 1 is -0.4, and the output never reaches 2.5.
Setup 2 and 3 on the other hand produce -1.2 as their first output value, and the value of 2.5 is surpassed on the first peek.
I don't know which of the disagreeing paries is right, or if they are both wrong. And I dont know if the base installation, numpy or control are to blame for the discrepany. And I am sorry my code does not show up properly. I was using the "code" button, but this does not seem to do anything usefull.
The text was updated successfully, but these errors were encountered: