From ffcc2a672bedcb1704cb762051a8893ed7a3381f Mon Sep 17 00:00:00 2001 From: Richard Murray Date: Fri, 4 Jul 2025 08:25:45 -0400 Subject: [PATCH 1/2] fix gh1161 by creating copy correctly --- control/optimal.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/control/optimal.py b/control/optimal.py index 3242ac3fb..6b60c5b25 100644 --- a/control/optimal.py +++ b/control/optimal.py @@ -746,9 +746,9 @@ def _compute_states_inputs(self, coeffs): states = self.last_states else: states = self._simulate_states(self.x, inputs) - self.last_x = self.x - self.last_states = states - self.last_coeffs = coeffs + self.last_x = self.x.copy() # save initial state + self.last_states = states # always a new object + self.last_coeffs = coeffs.copy() # save coefficients return states, inputs From a359e8ba328bfa87d35fc3d29ebb701237b8869b Mon Sep 17 00:00:00 2001 From: Richard Murray Date: Fri, 4 Jul 2025 09:18:58 -0400 Subject: [PATCH 2/2] fix rounding error issue showing up in NumPy 2.3.1 --- control/xferfcn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/control/xferfcn.py b/control/xferfcn.py index 02ba72df4..8e51534d7 100644 --- a/control/xferfcn.py +++ b/control/xferfcn.py @@ -1350,7 +1350,7 @@ def _c2d_matched(sysC, Ts, **kwargs): zpoles[idx] = z pregainden[idx] = 1 - z zgain = np.multiply.reduce(pregainnum) / np.multiply.reduce(pregainden) - gain = sysC.dcgain() / zgain + gain = sysC.dcgain() / zgain.real sysDnum, sysDden = zpk2tf(zzeros, zpoles, gain) return TransferFunction(sysDnum, sysDden, Ts, **kwargs)