Skip to content

Commit d35eec6

Browse files
committed
resolve conflict in tests/xferfcn_test.py
1 parent c36fcc0 commit d35eec6

File tree

8 files changed

+51
-12
lines changed

8 files changed

+51
-12
lines changed

control/bdalg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363

6464
def series(sys1, *sysn):
65-
"""Return the series connection (... \* sys3 \*) sys2 \* sys1
65+
"""Return the series connection (... \\* sys3 \\*) sys2 \\* sys1
6666
6767
Parameters
6868
----------

control/freqplot.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def bode_plot(syslist, omega=None,
110110
config.defaults['freqplot.number_of_samples'].
111111
margins : bool
112112
If True, plot gain and phase margin.
113-
\*args, \**kwargs:
113+
\\*args, \\*\\*kwargs:
114114
Additional options to matplotlib (color, linestyle, etc)
115115
116116
Returns
@@ -139,7 +139,7 @@ def bode_plot(syslist, omega=None,
139139
140140
2. If a discrete time model is given, the frequency response is plotted
141141
along the upper branch of the unit circle, using the mapping z = exp(j
142-
\omega dt) where omega ranges from 0 to pi/dt and dt is the discrete
142+
\\omega dt) where omega ranges from 0 to pi/dt and dt is the discrete
143143
timebase. If not timebase is specified (dt = True), dt is set to 1.
144144
145145
Examples
@@ -450,7 +450,7 @@ def nyquist_plot(syslist, omega=None, Plot=True, color=None,
450450
Used to specify the color of the plot
451451
labelFreq : int
452452
Label every nth frequency on the plot
453-
\*args, \**kwargs:
453+
\\*args, \\*\\*kwargs:
454454
Additional options to matplotlib (color, linestyle, etc)
455455
456456
Returns

control/grid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def zgrid(zetas=None, wns=None):
175175
an_x = xret[an_i]
176176
an_y = yret[an_i]
177177
num = '{:1.1f}'.format(a)
178-
ax.annotate("$\\frac{"+num+"\pi}{T}$", xy=(an_x, an_y), xytext=(an_x, an_y), size=9)
178+
ax.annotate(r"$\frac{"+num+r"\pi}{T}$", xy=(an_x, an_y), xytext=(an_x, an_y), size=9)
179179

180180
_final_setup(ax)
181181
return ax, fig

control/iosys.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ def _parse_signal(self, spec, signame='input', dictname=None):
12401240

12411241
if isinstance(spec, str):
12421242
# If we got a dotted string, break up into pieces
1243-
namelist = re.split('\.', spec)
1243+
namelist = re.split(r'\.', spec)
12441244

12451245
# For now, only allow signal level of system name
12461246
# TODO: expand to allow nested signal names

control/matlab/wrappers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def dcgain(*args):
130130
-------
131131
gain: ndarray
132132
The gain of each output versus each input:
133-
:math:`y = gain \cdot u`
133+
:math:`y = gain \\cdot u`
134134
135135
Notes
136136
-----
@@ -140,7 +140,7 @@ def dcgain(*args):
140140
All systems are first converted to state space form. The function then
141141
computes:
142142
143-
.. math:: gain = - C \cdot A^{-1} \cdot B + D
143+
.. math:: gain = - C \\cdot A^{-1} \\cdot B + D
144144
'''
145145
#Convert the parameters to state space form
146146
if len(args) == 4:

control/statefbk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def lqr(*args, **keywords):
341341
The lqr() function computes the optimal state feedback controller
342342
that minimizes the quadratic cost
343343
344-
.. math:: J = \int_0^\infty (x' Q x + u' R u + 2 x' N u) dt
344+
.. math:: J = \\int_0^\\infty (x' Q x + u' R u + 2 x' N u) dt
345345
346346
The function can be called with either 3, 4, or 5 arguments:
347347

control/tests/xferfcn_test.py

+25-2
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def test_evalfr_mimo(self):
449449
np.testing.assert_array_almost_equal(sys(2.j), resp)
450450

451451
def test_freqresp_siso(self):
452-
"""Evaluate the magnitude and phase of a SISO system at
452+
"""Evaluate the magnitude and phase of a SISO system at
453453
multiple frequencies."""
454454

455455
sys = TransferFunction([1., 3., 5], [1., 6., 2., -1])
@@ -467,7 +467,7 @@ def test_freqresp_siso(self):
467467

468468
@unittest.skipIf(not slycot_check(), "slycot not installed")
469469
def test_freqresp_mimo(self):
470-
"""Evaluate the magnitude and phase of a MIMO system at
470+
"""Evaluate the magnitude and phase of a MIMO system at
471471
multiple frequencies."""
472472

473473
num = [[[1., 2.], [0., 3.], [2., -1.]],
@@ -547,6 +547,7 @@ def test_common_den(self):
547547
np.zeros((3, 5, 6)))
548548
np.testing.assert_array_almost_equal(den, denref)
549549

550+
@unittest.skipIf(not slycot_check(), "slycot not installed")
550551
def test_pole_mimo(self):
551552
"""Test for correct MIMO poles."""
552553

@@ -804,6 +805,28 @@ def test_size_mismatch(self):
804805
self.assertRaises(NotImplementedError,
805806
TransferFunction.feedback, sys2, sys1)
806807

808+
def test_latex_repr(self):
809+
""" Test latex printout for TransferFunction """
810+
Hc = TransferFunction([1e-5, 2e5, 3e-4],
811+
[1.2e34, 2.3e-4, 2.3e-45])
812+
Hd = TransferFunction([1e-5, 2e5, 3e-4],
813+
[1.2e34, 2.3e-4, 2.3e-45],
814+
.1)
815+
# TODO: make the multiplication sign configurable
816+
expmul = r'\times'
817+
for var, H, suffix in zip(['s', 'z'],
818+
[Hc, Hd],
819+
['', r'\quad dt = 0.1']):
820+
ref = (r'$$\frac{'
821+
r'1 ' + expmul + ' 10^{-5} ' + var + '^2 '
822+
r'+ 2 ' + expmul + ' 10^{5} ' + var + ' + 0.0003'
823+
r'}{'
824+
r'1.2 ' + expmul + ' 10^{34} ' + var + '^2 '
825+
r'+ 0.00023 ' + var + ' '
826+
r'+ 2.3 ' + expmul + ' 10^{-45}'
827+
r'}' + suffix + '$$')
828+
self.assertEqual(H._repr_latex_(), ref)
829+
807830

808831
def suite():
809832
return unittest.TestLoader().loadTestsFromTestCase(TestXferFcn)

control/xferfcn.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
from copy import deepcopy
6262
from warnings import warn
6363
from itertools import chain
64+
from re import sub
6465
from .lti import LTI, timebaseEqual, timebase, isdtime
6566

6667
__all__ = ['TransferFunction', 'tf', 'ss2tf', 'tfdata']
@@ -301,6 +302,9 @@ def _repr_latex_(self, var=None):
301302
numstr = _tf_polynomial_to_string(self.num[i][j], var=var)
302303
denstr = _tf_polynomial_to_string(self.den[i][j], var=var)
303304

305+
numstr = _tf_string_to_latex(numstr, var=var)
306+
denstr = _tf_string_to_latex(denstr, var=var)
307+
304308
out += [r"\frac{", numstr, "}{", denstr, "}"]
305309

306310
if mimo and j < self.outputs - 1:
@@ -314,7 +318,7 @@ def _repr_latex_(self, var=None):
314318

315319
# See if this is a discrete time system with specific sampling time
316320
if not (self.dt is None) and type(self.dt) != bool and self.dt > 0:
317-
out += ["\quad dt = ", str(self.dt)]
321+
out += [r"\quad dt = ", str(self.dt)]
318322

319323
out.append("$$")
320324

@@ -1098,6 +1102,18 @@ def _tf_polynomial_to_string(coeffs, var='s'):
10981102
return thestr
10991103

11001104

1105+
def _tf_string_to_latex(thestr, var='s'):
1106+
""" make sure to superscript all digits in a polynomial string
1107+
and convert float coefficients in scientific notation
1108+
to prettier LaTeX representation """
1109+
# TODO: make the multiplication sign configurable
1110+
expmul = r' \\times'
1111+
thestr = sub(var + r'\^(\d{2,})', var + r'^{\1}', thestr)
1112+
thestr = sub(r'[eE]\+0*(\d+)', expmul + r' 10^{\1}', thestr)
1113+
thestr = sub(r'[eE]\-0*(\d+)', expmul + r' 10^{-\1}', thestr)
1114+
return thestr
1115+
1116+
11011117
def _add_siso(num1, den1, num2, den2):
11021118
"""Return num/den = num1/den1 + num2/den2.
11031119

0 commit comments

Comments
 (0)