GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Strange nondeterministic issues when using `phase_plot` with `X`, `Y` and `X0` set · Issue #970 · python-control/python-control

Strange nondeterministic issues when using phase_plot with X, Y and X0 set #970

New issue
Copy link
New issue
Copy link
Closed
#980
Closed
Strange nondeterministic issues when using phase_plot with X, Y and X0 set#970
#980
Copy link
Assignees
murrayrm

Description

@FeldrinH
FeldrinH
opened on Feb 13, 2024
Issue body actions

I am trying to draw a phase plot with both streamlines and a vector field. Using the inverted pendulum ODE from https://python-control.readthedocs.io/en/latest/phaseplots.html, I put together the following script:

import numpy as np
import matplotlib.pyplot as plt
from control.phaseplot import phase_plot

# Define the ODEs for a damped (inverted) pendulum
def invpend_ode(x, t, m=1., l=1., b=0.2, g=1):
    return x[1], -b/m*x[1] + (g*l/m)*np.sin(x[0])

# Set up the figure the way we want it to look
plt.figure()
plt.title('Inverted pendulum')

# Outer trajectories
phase_plot(
    invpend_ode,
    X=(-10, 10, 20),
    Y=(-10, 10, 20),
    X0=[[-2*np.pi, 1.6], [-2*np.pi, 0.5], [-1.8, 2.1],
        [-1, 2.1], [4.2, 2.1], [5, 2.1],
        [2*np.pi, -1.6], [2*np.pi, -0.5], [1.8, -2.1],
        [1, -2.1], [-4.2, -2.1], [-5, -2.1]]
)

plt.show()

I would have expected this to plot a simple vector field with a grid of 20*20 arrows and streamlines from the given inital conditions. Instead, each time I run this I get a different malformed plot, often with at least one axis somehow having arrows at values like 10^281. Various RuntimeWarnings about overflow are also sometimes printed in the console. Some examples of the plots I have gotten:

image
image
image
image
image

This does not seem like expected behaviour. What is going on here?

Tested on Windows 10 with Python 3.10.11, matplotlib 3.8.2 and control 0.9.4 from pip.

Activity

  1. FeldrinH
    changed the title [-]Strange nondeterministic behavior when using `phase_plot` with `X`, `Y` and `X0` set.[/-] [+]Strange nondeterministic behavior when using `phase_plot` with `X`, `Y` and `X0` set[/+] on Feb 13, 2024
  2. FeldrinH
    changed the title [-]Strange nondeterministic behavior when using `phase_plot` with `X`, `Y` and `X0` set[/-] [+]Strange nondeterministic issues when using `phase_plot` with `X`, `Y` and `X0` set[/+] on Feb 13, 2024
  3. murrayrm commented on Feb 18, 2024

    @murrayrm
    murrayrm
    on Feb 18, 2024
    Member
    More actions

    I ran this on the current main and got similar behavior on MacOS 14.2 with Python 3.11. There are a couple of warning messages that also appear

    [...]/matplotlib/quiver.py:646: RuntimeWarning: divide by zero encountered in scalar divide
      length = a * (widthu_per_lenu / (self.scale * self.width))
    [...]/matplotlib/quiver.py:646: RuntimeWarning: invalid value encountered in multiply
      length = a * (widthu_per_lenu / (self.scale * self.width))
    

    These could be the source of the randomness?

    I'll try to have a look and see if I can figure out what is going on and see if there is a quick fix. I'm in the process of rewriting this functionality to be a bit more Pythonic, so it may not make sense to do an interim fix to the old code. More info as I find it.

    Reacted by Ben Greiner and Juhan Oskar Hennoste
  4. bnavigator
    assigned
    murrayrm
    on Feb 18, 2024
  5. murrayrm
    linked a pull request that will close this issueReimplementation of 2D phase plots #980on Mar 28, 2024
  6. murrayrm
    closed this as completedin #980on Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @murrayrm
    murrayrm

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402520 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.