Skip to content

Commit 4de4c0e

Browse files
committed
fixed ticked #6, evalfr does not behave as expected
1 parent a10a0fd commit 4de4c0e

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

src/matlab.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -889,16 +889,20 @@ def zero(sys):
889889

890890
return sys.zero()
891891

892-
def evalfr(sys, omega):
892+
def evalfr(sys, x):
893893
"""
894-
Evaluate the transfer function of an LTI system at an angular frequency.
894+
Evaluate the transfer function of an LTI system for a single complex
895+
number x.
896+
897+
To evaluate at a frequency, enter x = omega*j, where omega is the
898+
frequency in radians
895899
896900
Parameters
897901
----------
898902
sys: StateSpace or TransferFunction
899903
Linear system
900-
omega: scalar
901-
Frequency
904+
x: scalar
905+
Complex number
902906
903907
Returns
904908
-------
@@ -917,14 +921,16 @@ def evalfr(sys, omega):
917921
Examples
918922
--------
919923
>>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
920-
>>> evalfr(sys, 1.)
924+
>>> evalfr(sys, 1j)
921925
array([[ 44.8-21.4j]])
922926
>>> # This is the transfer function matrix evaluated at s = i.
923927
924928
.. todo:: Add example with MIMO system
925929
"""
926-
927-
return sys.evalfr(omega)
930+
if issiso(sys):
931+
return sys.horner(x)[0][0]
932+
return sys.horner(x)
933+
928934

929935
def freqresp(sys, omega):
930936
"""

tests/matlab_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,16 @@ def testFreqresp(self):
316316
freqresp(self.siso_tf3, w)
317317

318318
def testEvalfr(self):
319-
w = 1
320-
evalfr(self.siso_ss1, w)
319+
w = 1j
320+
self.assertEqual(evalfr(self.siso_ss1, w), 44.8-21.4j)
321321
evalfr(self.siso_ss2, w)
322322
evalfr(self.siso_ss3, w)
323323
evalfr(self.siso_tf1, w)
324324
evalfr(self.siso_tf2, w)
325325
evalfr(self.siso_tf3, w)
326+
np.testing.assert_array_almost_equal(
327+
evalfr(self.mimo_ss1, w),
328+
np.array( [[44.8-21.4j, 0.], [0., 44.8-21.4j]]))
326329

327330
def testHsvd(self):
328331
hsvd(self.siso_ss1)

0 commit comments

Comments
 (0)