Skip to content

Fix find_eqpt when y0 is None #798

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

Merged
merged 1 commit into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions control/iosys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2138,10 +2138,15 @@ def rootfun(z):
dx = sys._rhs(t, x, u) - dx0
if dtime:
dx -= x # TODO: check
dy = sys._out(t, x, u) - y0

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

# Map the results into the constrained variables
return np.concatenate((dx[deriv_vars], dy[output_vars]), axis=0)

# Set the initial condition for the root finding algorithm
z0 = np.concatenate((x[state_vars], u[input_vars]), axis=0)
Expand Down
11 changes: 11 additions & 0 deletions control/tests/iosys_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,17 @@ def test_find_eqpts(self, tsys):
np.testing.assert_array_almost_equal(
nlsys_full._rhs(0, xeq, ueq)[-4:], np.zeros((4,)), decimal=5)

# The same test as previous, but now all constraints are in the state vector
nlsys_full = ios.NonlinearIOSystem(pvtol_full, None)
xeq, ueq, result = ios.find_eqpt(
nlsys_full, [0, 0, 0.1, 0.1, 0, 0], [0.01, 4*9.8],
idx=[2, 3, 4, 5], ix=[0, 1, 2, 3], return_result=True)
assert result.success
np.testing.assert_array_almost_equal(
nlsys_full._out(0, xeq, ueq)[[2, 3]], [0.1, 0.1], decimal=5)
np.testing.assert_array_almost_equal(
nlsys_full._rhs(0, xeq, ueq)[-4:], np.zeros((4,)), decimal=5)

# Fix one input and vary the other
nlsys_full = ios.NonlinearIOSystem(pvtol_full, None)
xeq, ueq, result = ios.find_eqpt(
Expand Down