7373import numpy as np # NumPy library
7474import warnings
7575from .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 ]
0 commit comments