8000 Merge pull request #798 from adswid/fix-find_eqpt · python-control/python-control@23a7791 · GitHub
[go: up one dir, main page]

Skip to content

Commit 23a7791

Browse files
authored
Merge pull request #798 from adswid/fix-find_eqpt
Fix find_eqpt when y0 is None
2 parents 832527d + 57ad2f1 commit 23a7791

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

control/iosys.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,10 +2138,15 @@ def rootfun(z):
21382138
dx = sys._rhs(t, x, u) - dx0
21392139
if dtime:
21402140
dx -= x # TODO: check
2141-
dy = sys._out(t, x, u) - y0
21422141

2143-
# Map the results into the constrained variables
2144-
return np.concatenate((dx[deriv_vars], dy[output_vars]), axis=0)
2142+
# If no y0 is given, don't evaluate the output function
2143+
if y0 is None:
2144+
return dx[deriv_vars]
2145+
else:
2146+
dy = sys._out(t, x, u) - y0
2147+
2148+
# Map the results into the constrained variables
2149+
return np.concatenate((dx[deriv_vars], dy[output_vars]), axis=0)
21452150

21462151
# Set the initial condition for the root finding algorithm
21472152
z0 = np.concatenate((x[state_vars], u[input_vars]), axis=0)

control/tests/iosys_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,17 @@ def test_find_eqpts(self, tsys):
822822
np.testing.assert_array_almost_equal(
823823
nlsys_full._rhs(0, xeq, ueq)[-4:], np.zeros((4,)), decimal=5)
824824

825+
# The same test as previous, but now all constraints are in the state vector
826+
nlsys_full = ios.NonlinearIOSystem(pvtol_full, None)
827+
xeq, ueq, result = ios.find_eqpt(
828+
nlsys_full, [0, 0, 0.1, 0.1, 0, 0], [0.01, 4*9.8],
829+
idx=[2, 3, 4, 5], ix=[0, 1, 2, 3], return_result=True)
830+
assert result.success
831+
np.testing.assert_array_almost_equal(
832+
nlsys_full._out(0, xeq, ueq)[[2, 3]], [0.1, 0.1], decimal=5)
833+
np.testing.assert_array_almost_equal(
834+
nlsys_full._rhs(0, xeq, ueq)[-4:], np.zeros((4,)), decimal=5)
835+
825836
# Fix one input and vary the other
826837
nlsys_full = ios.NonlinearIOSystem(pvtol_full, None)
827838
xeq, ueq, result = ios.find_eqpt(

0 commit comments

Comments
 (0)
0