Skip to content

Commit 385c9e9

Browse files
committed
Updated changelog
1 parent e722b28 commit 385c9e9

File tree

4 files changed

+75
-3
lines changed

4 files changed

+75
-3
lines changed

ChangeLog

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
2013-05-23 Rene van Paassen <rene.vanpaassen@gmail.com>
2+
3+
* src/margin.py: re-vamped stability_margins function. Now
4+
uses analytical method for TF and state-space, works on FRD
5+
objects too, and can optionally return all margins found for
6+
the analytical method.
7+
8+
* src/xferfcn.py and src/frdata.py: Now return array result
9+
for fresp when called with an iterable frequency vector
10+
11+
* src/xferfcn.py and src/statesp.py: added minreal functions
12+
13+
* src/bdalg.py: implemented append and connect functions (old
14+
version, with indexes, not with names)
15+
16+
* src/matlab.py: added connect, append, minreal
17+
118
2012-11-10 Richard Murray <murray@altura.local>
219

320
* src/canonical.py: new module implementing conversions to selected

src/matlab.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
from control.pzmap import pzmap
102102
from control.statefbk import ctrb, obsv, gram, place, lqr
103103
from control.delay import pade
104-
from control.modelsimp import hsvd, balred, modred
104+
from control.modelsimp import hsvd, balred, modred, minreal
105105
from control.mateqn import lyap, dlyap, dare, care
106106

107107
__doc__ += r"""
@@ -244,7 +244,7 @@
244244
----------------------------------------------------------------------------
245245
246246
== ========================== ============================================
247-
\ minreal minimal realization; pole/zero cancellation
247+
\* :func:`~modelsimp.minreal` minimal realization; pole/zero cancellation
248248
\ ss/sminreal structurally minimal realization
249249
\* :func:`~modelsimp.hsvd` hankel singular values (state contributions)
250250
\* :func:`~modelsimp.balred` reduced-order approximations of LTI models

src/modelsimp.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,33 @@ def balred(sys, orders, method='truncate'):
269269

270270
return rsys
271271

272+
def minreal(sys, tol=None, verbose=True):
273+
'''
274+
Eliminates uncontrollable or unobservable states in state-space
275+
models or cancelling pole-zero pairs in transfer functions. The
276+
output sysr has minimal order and the same response
277+
characteristics as the original model sys.
278+
279+
Parameters
280+
----------
281+
sys: StateSpace or TransferFunction
282+
Original system
283+
tol: real
284+
Tolerance
285+
verbose: bool
286+
Print results if True
287+
288+
Returns
289+
-------
290+
rsys: StateSpace or TransferFunction
291+
Cleaned model
292+
'''
293+
sysr = sys.minreal(tol)
294+
if verbose:
295+
print("{nstates} states have been removed from the model".format(
296+
nstates=len(sys.pole()) - len(sysr.pole())))
297+
return sysr
298+
272299
def era(YY, m, n, nin, nout, r):
273300
"""
274301
Calculate an ERA model of order `r` based on the impulse-response data `YY`.

tests/matlab_test.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from __future__ import print_function
1212
import unittest
1313
import numpy as np
14+
from scipy.linalg import eigvals
1415
import scipy as sp
1516
from control.matlab import *
1617
from control.frdata import FRD
@@ -440,7 +441,34 @@ def testFRD(self):
440441
assert isinstance(frd1, FRD)
441442
frd2 = frd(frd1.fresp[0,0,:], omega)
442443
assert isinstance(frd2, FRD)
443-
444+
445+
def testMinreal(self, verbose=False):
446+
"""Test a minreal model reduction"""
447+
#A = [-2, 0.5, 0; 0.5, -0.3, 0; 0, 0, -0.1]
448+
A = [[-2, 0.5, 0], [0.5, -0.3, 0], [0, 0, -0.1]]
449+
#B = [0.3, -1.3; 0.1, 0; 1, 0]
450+
B = [[0.3, -1.3], [0.1, 0.], [1.0, 0.0]]
451+
#C = [0, 0.1, 0; -0.3, -0.2, 0]
452+
C = [[0., 0.1, 0.0], [-0.3, -0.2, 0.0]]
453+
#D = [0 -0.8; -0.3 0]
454+
D = [[0., -0.8], [-0.3, 0.]]
455+
# sys = ss(A, B, C, D)
456+
457+
sys = ss(A, B, C, D)
458+
sysr = minreal(sys)
459+
self.assertEqual(sysr.states, 2)
460+
self.assertEqual(sysr.inputs, sys.inputs)
461+
self.assertEqual(sysr.outputs, sys.outputs)
462+
np.testing.assert_array_almost_equal(
463+
eigvals(sysr.A), [-2.136154, -0.1638459])
464+
465+
s = tf([1, 0], [1])
466+
h = (s+1)*(s+2.00000000001)/(s+2)/(s**2+s+1)
467+
hm = minreal(h)
468+
hr = (s+1)/(s**2+s+1)
469+
np.testing.assert_array_almost_equal(hm.num[0][0], hr.num[0][0])
470+
np.testing.assert_array_almost_equal(hm.den[0][0], hr.den[0][0])
471+
444472

445473
#! TODO: not yet implemented
446474
# def testMIMOtfdata(self):

0 commit comments

Comments
 (0)