Skip to content
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

Better I/O systems support for phase plots #1001

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

murrayrm
Copy link
Member

@murrayrm murrayrm commented May 11, 2024

This PR provides better I/O systems support for making phase plots:

  • Allow I/O systems with no inputs and/or no outputs to be specified. This is useful when generating phase plots, where you might just have a simple dynamical systems but still want to use the I/O system objects.
  • Improve the error messages in input_output_response when the number of states, inputs, or outputs are incompatible with the system size by telling you which one didn't match.
  • Generate warnings when simulations fail for individual initial conditions and drop individual trace (rather than terminating). This yields much nicer phase plane plots by allowing the system to generate lines when it can and ignoring the rest.
  • Added Jupyter notebook analyzing open and closed loop dynamics of an inverted pendulum, showing off some of the capabilities of the package.
  • Changed the way plot titles are created, using axes.set_title (centers title over axes) instead of fig.suptitle (centers over figure, which is good for multi-axes plots but otherwise looks funny). I'll propagate this same change to time plots and frequency plots in separate PRs.
  • Did some tweaking on arrow placement so that very short lines have zero or one arrows. Could use more work, but this is better than what we had.

As an example of the changes, here is the code to produce a phase portrait for the inverted pendulum example in FBS2e, Figure 5.4:

from math import pi
import control as ct
def invpend_update(t, x, u, params):
    m, l, b, g = params['m'], params['l'], params['b'], params['g']
    return [x[1], -b/m * x[1] + (g * l / m) * np.sin(x[0])]
invpend = ct.nlsys(
    invpend_update, states=2, inputs=0, name='invpend',
    params={'m': 1, 'l': 1, 'b': 0.2, 'g': 1})

ct.phase_plane_plot(invpend, [-2*pi - 1, 2*pi + 1, -2, 2], 10)

Before:
invpend_before

After:
invpend_after

The changes are not major, but if you look at the number and spacing of arrows along the streamlines, you'll see examples of the changes there (some streamlines have no arrows in "before" plot). Also note the change in location of the title.

@coveralls
Copy link

coveralls commented May 11, 2024

Coverage Status

coverage: 94.522% (+0.02%) from 94.503%
when pulling c72fa91 on murrayrm:phaseplot_improvements-16Apr2024
into e4a03e8 on python-control:main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants