Skip to content

Commit fa100df

Browse files
committed
Added fival() function
Added the fival() function at the bottom of thetimeresp.py file, slightly adjusting it to conform with the existing imports in the file and adding a couple of new import statements. Adjusted the documentation so that its format is conform with the rest of the file. Slightly adjusted the format of the documentation for clean_tf() in the xferfcn.py file
1 parent d3aaafb commit fa100df

2 files changed

Lines changed: 60 additions & 4 deletions

File tree

control/timeresp.py

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@
7373
import numpy as np # NumPy library
7474
import warnings
7575
from .lti import LTI # base class of StateSpace, TransferFunction
76-
from .statesp import _convertToStateSpace, _mimo2simo, _mimo2siso, ssdata
77-
from .lti import isdtime, isctime
76+
from .statesp import _convertToStateSpace, _mimo2simo, _mimo2siso, ssdata, StateSpace
77+
from .lti import isdtime, isctime, pole
78+
from .xferfcn import TransferFunction, tf, clean_tf
7879

7980
__all__ = ['forced_response', 'step_response', 'step_info', 'initial_response',
8081
'impulse_response']
@@ -882,4 +883,58 @@ def _default_time_vector(sys, N=None, tfinal=None):
882883
if N is None:
883884
N = int(np.clip(tfinal/ideal_dt, N_min_ct, N_max)) # N<-[N_min, N_max]
884885

885-
return np.linspace(0, tfinal, N, endpoint=False)
886+
return np.linspace(0, tfinal, N, endpoint=False)
887+
888+
889+
def fival(sys, forcing="step", input=1, output=1, stabilityCheck=False, precision=10):
890+
"""
891+
Returns the final value of a state space or transfer function. It is based on the mathematical final value theorem
892+
and is thus faster and avoids unnecessarily large time vectors. For MIMO systems one can prescribe which input and
893+
output are desired.
894+
895+
Parameters
896+
----------
897+
sys : LTI (StateSpace, or TransferFunction)
898+
LTI system whose data will be returned
899+
forcing: A SISO TransferFunction
900+
Laplace transform of the forcingunction describing the input
901+
input : integer
902+
Refers to the requested input (starting from 1), 1 by default
903+
output : integer
904+
Refers to the requested output (starting from 1), 1 by default
905+
stabilityCheck : bool
906+
If True it is checked if the system is stable. The final value theorem gives
907+
erroneous results for unstable systems
908+
precision : integer
909+
Number of decimals to be left unchanged in rounding
910+
911+
Returns
912+
-------
913+
out : float or inf
914+
The final value of the system. inf has the correct sign
915+
916+
Raises
917+
------
918+
TypeError
919+
if sys is not a StateSpace or TransferFunction object
920+
TypeError
921+
if forcing is not a TransferFunction object
922+
"""
923+
924+
if (type(sys) is not TransferFunction) and (type(sys) is not StateSpace):
925+
raise TypeError("Neither a StateSpace nor TransferFunction was passed to 'sys'")
926+
if forcing != "step" and (type(forcing) is not TransferFunction):
927+
raise TypeError("The input passed to 'forcing' is not a TransferFunction")
928+
929+
cleaned_sys = clean_tf(sys, input=input, output=output, precision=precision)
930+
if stabilityCheck:
931+
p = np.real(pole(cleaned_sys))
932+
if len(p[p > 0]) != 0:
933+
return print("Unstable system due to ", len(p[p > 0]), " poles in the right half of the complex plane")
934+
if len(p[p == 0]) > 1:
935+
return print("Unstable system due to ", len(p[p == 0]), " poles at the origin")
936+
if forcing != "step":
937+
cleaned_sys = cleaned_sys * forcing * tf([1, 0], [1])
938+
if cleaned_sys.den[0][0][-1] == 0:
939+
return np.inf * np.sign(cleaned_sys.num[0][0][-1])
940+
return cleaned_sys.num[0][0][-1] / cleaned_sys.den[0][0][-1]

control/xferfcn.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,8 +1593,9 @@ def clean_tf(sys, input=None, output=None, precision=10):
15931593
TypeError
15941594
if sys is not a StateSpace or TransferFunction object
15951595
"""
1596+
15961597
if (type(sys) is not TransferFunction) and (type(sys) is not StateSpace):
1597-
raise Exception("Neither a StateSpace nor TransferFunction was passed to 'sys'")
1598+
raise TypeError("Neither a StateSpace nor TransferFunction was passed to 'sys'")
15981599

15991600
sys = tf(sys).minreal()
16001601
if input is not None and output is not None:

0 commit comments

Comments
 (0)