Skip to content

Commit 15e5cba

Browse files
committed
beginnings of code starts with a docstring
1 parent d3142ff commit 15e5cba

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

control/timeresp.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,57 @@ def impulse_response(sys, T=None, X0=0., input=0, output=None, T_num=None,
826826
return T, yout
827827

828828
# utility function to find time period and time increment using pole locations
829-
def _ideal_tfinal_and_dt(sys):
829+
def _ideal_tfinal_and_dt(sys, is_step=True):
830+
"""helper function to compute ideal simulation duration tfinal and dt, the
831+
time increment. Usually called by _default_time_vector, whose job it is to
832+
bring reality into the picture.
833+
834+
For discrete-time models, dt is inherent and only tfinal is computed.
835+
836+
Parameters
837+
----------
838+
sys : StateSpace or TransferFunction
839+
The system whose time response is to be computed
840+
is_step : bool
841+
Scales the dc value by the magnitude of the nonzero mode since
842+
integrating the impulse response gives ∫exp(-λt) = -exp(-λt)/λ.
843+
Default is True.
844+
Returns
845+
-------
846+
tfinal : float
847+
The final time instance for which the simulation will be performed.
848+
dt : float
849+
The estimated sampling period for the simulation.
850+
851+
Notes
852+
-----
853+
Just by evaluating the fastest mode for dt and slowest for tfinal often
854+
leads to unnecessary, bloated sampling (e.g., Transfer(1,[1,1001,1000]))
855+
since dt will be very small and tfinal will be too large though the fast
856+
mode hardly ever contributes. Similarly, change the numerator to [1, 2, 0]
857+
and the simulation would be unnecessarily long and the plot is virtually
858+
an L shape since the decay is so fast.
859+
860+
Instead, a modal decomposition in time domain hence a truncated ZIR and ZSR
861+
can be used such that only the modes that have significant effect on the
862+
time response are taken. But the sensitivity of the eigenvalues complicate
863+
the matter since dλ = <w, dA*v> with <w,v> = 1. Hence we can only work
864+
with simple poles with this formulation. See Golub, Van Loan Section 7.2.2
865+
for simple eigenvalue sensitivity about the nonunity of <w,v>. The size of
866+
the response is dependent on the size of the eigenshapes rather than the
867+
eigenvalues themselves.
868+
869+
By Ilhan Polat, with modifications by Sawyer Fuller to integrate into
870+
python-control 2020.08.17
871+
"""
872+
873+
sqrt_eps = np.sqrt(np.spacing(1.))
874+
default_tfinal = 5 # Default simulation horizon
875+
total_cycles = 5 # number of cycles for oscillating modes
876+
pts_per_cycle = 25 # Number of points divide a period of oscillation
877+
log_decay_percent = np.log(100) # Factor of reduction for real pole decays
878+
879+
if sys.is_static_gain(): pass
830880
constant = 7.0
831881
tolerance = 1e-10
832882
A = ssdata(sys)[0]

0 commit comments

Comments
 (0)