Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

more parameters for series and parallel (updated)#185

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
14 commits
Select commitHold shift + click to select a range
f167b2e
Update bdalg.py
MarxlpMar 7, 2017
558c1b9
Merge branch 'master' of https://github.com/python-control/python-con…
murrayrmJan 2, 2018
54d41aa
Merge branch 'master' of https://github.com/python-control/python-con…
murrayrmJan 2, 2018
9405886
Merge branch 'master' of https://github.com/python-control/python-con…
murrayrmJan 3, 2018
2bb70cf
Merge branch 'patch-1' of https://github.com/Marxlp/python-control in…
murrayrmJan 3, 2018
6bb6d5c
DOC: slight tweaks to documentation, for consistency
murrayrmJan 3, 2018
3c0fa80
TRV: updated to 4-space indentation units
murrayrmJan 3, 2018
44dd3e6
TST: added simple unit tests for series, parallel
murrayrmJan 3, 2018
ee30983
Merge branch 'master' of https://github.com/python-control/python-con…
murrayrmJan 5, 2018
0eb5f1f
more parameters for series and parallel
MarxlpJan 6, 2018
2a6143f
Merge branch 'master' of https://github.com/python-control/python-con…
murrayrmJan 6, 2018
52c5058
Merge branch 'more-parameters' of https://github.com/Marxlp/python-co…
murrayrmJan 6, 2018
be3bea5
Slight modifications to
murrayrmJan 6, 2018
ccb84a2
DOC: small docstring tweaks
murrayrmJan 6, 2018
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
30 changes: 17 additions & 13 deletionscontrol/bdalg.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,13 +61,13 @@

__all__ = ['series', 'parallel', 'negate', 'feedback', 'append', 'connect']

def series(sys1,sys2):
"""Return the series connectionsys2 *sys1 for --> sys1 -->sys2-->.
def series(sys1,*sysn):
"""Return the series connection(... *sys3 *)sys2* sys1

Parameters
----------
sys1: scalar, StateSpace, TransferFunction, or FRD
sys2: scalar, StateSpace, TransferFunction, orFRD
*sysn: other scalers, StateSpaces, TransferFunctions, orFRDs

Returns
-------
Expand DownExpand Up@@ -97,20 +97,22 @@ def series(sys1, sys2):

Examples
--------
>>> sys3 = series(sys1, sys2) # Same as sys3 = sys2 * sys1.
>>> sys3 = series(sys1, sys2) # Same as sys3 = sys2 * sys1

"""
>>> sys5 = series(sys1, sys2, sys3, sys4) # More systems

return sys2 * sys1
"""
from functools import reduce
return reduce(lambda x, y:x*y, sysn, sys1)

def parallel(sys1,sys2):
def parallel(sys1,*sysn):
"""
Return the parallel connection sys1 + sys2.
Return the parallel connection sys1 + sys2 (+ sys3 + ...)

Parameters
----------
sys1: scalar, StateSpace, TransferFunction, or FRD
sys2: scalar, StateSpace, TransferFunction, orFRD
*sysn: other scalers, StateSpaces, TransferFunctions, orFRDs

Returns
-------
Expand DownExpand Up@@ -140,11 +142,13 @@ def parallel(sys1, sys2):

Examples
--------
>>> sys3 = parallel(sys1, sys2) # Same as sys3 = sys1 + sys2.
>>> sys3 = parallel(sys1, sys2) # Same as sys3 = sys1 + sys2

"""
>>> sys5 = parallel(sys1, sys2, sys3, sys4) # More systems

return sys1 + sys2
"""
from functools import reduce
return reduce(lambda x, y:x+y, sysn, sys1)

def negate(sys):
"""
Expand DownExpand Up@@ -247,7 +251,7 @@ def feedback(sys1, sys2=1, sign=-1):
return sys1.feedback(sys2, sign)

def append(*sys):
'''append(sys1, sys2, ... sysn)
'''append(sys1, sys2, ..., sysn)

Group models by appending their inputs and outputs

Expand Down
60 changes: 60 additions & 0 deletionscontrol/tests/bdalg_test.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,9 +5,12 @@

import unittest
import numpy as np
from numpy import sort
import control as ctrl
from control.xferfcn import TransferFunction
from control.statesp import StateSpace
from control.bdalg import feedback
from control.lti import zero, pole

class TestFeedback(unittest.TestCase):
"""These are tests for the feedback function in bdalg.py. Currently, some
Expand DownExpand Up@@ -177,6 +180,63 @@ def testTFTF(self):
np.testing.assert_array_almost_equal(ans2.num, [[[1., 4., 7., 6.]]])
np.testing.assert_array_almost_equal(ans2.den, [[[1., 4., 9., 8., 5.]]])

def testLists(self):
"""Make sure that lists of various lengths work for operations"""
sys1 = ctrl.tf([1, 1], [1, 2])
sys2 = ctrl.tf([1, 3], [1, 4])
sys3 = ctrl.tf([1, 5], [1, 6])
sys4 = ctrl.tf([1, 7], [1, 8])
sys5 = ctrl.tf([1, 9], [1, 0])

# Series
sys1_2 = ctrl.series(sys1, sys2)
np.testing.assert_array_almost_equal(sort(pole(sys1_2)), [-4., -2.])
np.testing.assert_array_almost_equal(sort(zero(sys1_2)), [-3., -1.])

sys1_3 = ctrl.series(sys1, sys2, sys3);
np.testing.assert_array_almost_equal(sort(pole(sys1_3)),
[-6., -4., -2.])
np.testing.assert_array_almost_equal(sort(zero(sys1_3)),
[-5., -3., -1.])

sys1_4 = ctrl.series(sys1, sys2, sys3, sys4);
np.testing.assert_array_almost_equal(sort(pole(sys1_4)),
[-8., -6., -4., -2.])
np.testing.assert_array_almost_equal(sort(zero(sys1_4)),
[-7., -5., -3., -1.])

sys1_5 = ctrl.series(sys1, sys2, sys3, sys4, sys5);
np.testing.assert_array_almost_equal(sort(pole(sys1_5)),
[-8., -6., -4., -2., -0.])
np.testing.assert_array_almost_equal(sort(zero(sys1_5)),
[-9., -7., -5., -3., -1.])

# Parallel
sys1_2 = ctrl.parallel(sys1, sys2)
np.testing.assert_array_almost_equal(sort(pole(sys1_2)), [-4., -2.])
np.testing.assert_array_almost_equal(sort(zero(sys1_2)),
sort(zero(sys1 + sys2)))

sys1_3 = ctrl.parallel(sys1, sys2, sys3);
np.testing.assert_array_almost_equal(sort(pole(sys1_3)),
[-6., -4., -2.])
np.testing.assert_array_almost_equal(sort(zero(sys1_3)),
sort(zero(sys1 + sys2 + sys3)))

sys1_4 = ctrl.parallel(sys1, sys2, sys3, sys4);
np.testing.assert_array_almost_equal(sort(pole(sys1_4)),
[-8., -6., -4., -2.])
np.testing.assert_array_almost_equal(sort(zero(sys1_4)),
sort(zero(sys1 + sys2 +
sys3 + sys4)))


sys1_5 = ctrl.parallel(sys1, sys2, sys3, sys4, sys5);
np.testing.assert_array_almost_equal(sort(pole(sys1_5)),
[-8., -6., -4., -2., -0.])
np.testing.assert_array_almost_equal(sort(zero(sys1_5)),
sort(zero(sys1 + sys2 +
sys3 + sys4 + sys5)))
def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestFeedback)

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp