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 — Result of the damp function for discrete time systems · Issue #646 · python-control/python-control

Result of the damp function for discrete time systems #646

New issue
Copy link
New issue
Copy link
Closed
#647
Closed
Result of the damp function for discrete time systems#646
#647
Copy link
Labels
bug

Description

@vincentchoqueuse
vincentchoqueuse
opened on Aug 17, 2021
Issue body actions

Hi,

This is my first contribution on GitHub ;)

Problem

The method damp() seems to return a wrong result for discrete systems with negative poles

import control as ctl
H = ctl.tf([1],[1,0.2],1)
H.damp()

Result : RuntimeWarning: invalid value encountered in log

Investigation

The problem seems to come from the type of the poles variable in the dampmethod of the LTI object

if isdtime(self, strict=True):
     splane_poles = np.log(poles)/self.dt
else:
      splane_poles = poles
wn = absolute(splane_poles)
Z = -real(splane_poles)/wn
return wn, Z, poles

Solution

The poles variable must be cast to a numpy complex type as follows

if isdtime(self, strict=True)
      splane_poles = np.log(poles.astype(complex))/self.dt
...

Activity

  1. bnavigator commented on Aug 17, 2021

    @bnavigator
    bnavigator
    on Aug 17, 2021
    Contributor
    More actions

    Hi,

    thanks for catching this!

    This is my first contribution on GitHub ;)

    Awesome! Would you try to make the next step and create a Pull Request with your proposed changes?

    Bonus points for adding your example to test_damp() (using pytest.mark.parametrize()) :

    python-control/control/tests/lti_test.py

    Lines 54 to 71 in 6b7a9c7

    def test_damp(self):
    # Test the continuous time case.
    zeta = 0.1
    wn = 42
    p = -wn * zeta + 1j * wn * np.sqrt(1 - zeta**2)
    sys = tf(1, [1, 2 * zeta * wn, wn**2])
    expected = ([wn, wn], [zeta, zeta], [p, p.conjugate()])
    np.testing.assert_allclose(sys.damp(), expected)
    np.testing.assert_allclose(damp(sys), expected)
    # Also test the discrete time case.
    dt = 0.001
    sys_dt = c2d(sys, dt, method='matched')
    p_zplane = np.exp(p*dt)
    expected_dt = ([wn, wn], [zeta, zeta],
    [p_zplane, p_zplane.conjugate()])
    np.testing.assert_almost_equal(sys_dt.damp(), expected_dt)
    np.testing.assert_almost_equal(damp(sys_dt), expected_dt)

  2. bnavigator
    linked a pull request that will close this issuefix damp method for discrete time systems with a negative real-valued pole #647on Aug 17, 2021
  3. bnavigator
    added
    bug
    on Aug 17, 2021
  4. bnavigator
    closed this as completedin #647on Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — 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.