8000 Add ab04md by KybernetikJo · Pull Request #201 · python-control/Slycot · GitHub
[go: up one dir, main page]

Skip to content

Add ab04md #201

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 8 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Unittest added for ab04md.
  • Loading branch information
KybernetikJo committed Aug 23, 2023
commit 52cc0f8fae101ee03dd2013bb83e43cc51527a4c
1 change: 1 addition & 0 deletions slycot/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(PYSOURCE

__init__.py
test_ab01.py
test_ab04md.py
test_ab08n.py
test_ag08bd.py
test_examples.py
Expand Down
71 changes: 71 additions & 0 deletions 10000 slycot/tests/test_ab04md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# ===================================================
# ab08n* tests

import unittest
from slycot import analysis
import numpy as np

from scipy.linalg import eig
from numpy.testing import assert_equal, assert_allclose


class test_ab04md(unittest.TestCase):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unittest.TestCase not needed

"""Test ab04md.

Example data taken from
https://www.slicot.org/objects/software/shared/doc/AB04MD.html.
"""

Ac = np.array([[1.0, 0.5],
[0.5, 1.0]])
Bc = np.array([[0.0, -1.0],
[1.0, 0.0]])
Cc = np.array([[-1.0, 0.0],
[0.0, 1.0]])
Dc = np.array([[1.0, 0.0],
[0.0, -1.0]])

Ad = np.array([[-1.0, -4.0],
[-4.0, -1.0]])
Bd = np.array([[2.8284, 0.0],
[0.0, -2.8284]])
Cd = np.array([[0.0, 2.8284],
[-2.8284, 0.0]])
Dd = np.array([[-1.0, 0.0],
[0.0, -3.0]])

def test_ab04md_cont_disc_cont(self):
"""Test transformation from continuous - to discrete - to continuous time.
"""

n, m = self.Bc.shape
p = self.Cc.shape[0]

Ad_t, Bd_t, Cd_t, Dd_t = analysis.ab04md('C',n,m,p,self.Ac,self.Bc,self.Cc,self.Dc)

Ac_t, Bc_t, Cc_t, Dc_t = analysis.ab04md('D',n,m,p,Ad_t,Bd_t,Cd_t,Dd_t)

assert_allclose(self.Ac, Ac_t)
assert_allclose(self.Bc, Bc_t)
assert_allclose(self.Cc, Cc_t)
assert_allclose(self.Dc, Dc_t)

def test_ab04md_disc_cont_disc(self):
"""Test transformation from discrete - to continuous - to discrete time.
"""

n, m = self.Bc.shape
p = self.Cc.shape[0]

Ac_t, Bc_t, Cc_t, Dc_t = analysis.ab04md('D',n,m,p,self.Ad,self.Bd,self.Cd,self.Dd)

Ad_t, Bd_t, Cd_t, Dd_t = analysis.ab04md('C',n,m,p,Ac_t,Bc_t,Cc_t,Dc_t)

assert_allclose(self.Ad, Ad_t)
assert_allclose(self.Bd, Bd_t)
assert_allclose(self.Cd, Cd_t)
assert_allclose(self.Dd, Dd_t)


if __name__ == "__main__":
unittest.main()
0