Skip to content

Commit

Permalink
move warning to before conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
bnavigator committed Mar 25, 2021
1 parent fa58099 commit a09e98c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions control/timeresp.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ def forced_response(sys, T=None, U=0., X0=0., transpose=False,
"return_x specified for a transfer function system. Internal "
"conversion to state space used; results may meaningless.")

# If we are passed a transfer function and X0 is non-zero, warn the user
if isinstance(sys, TransferFunction) and np.any(X0 != 0):
warnings.warn(
"Non-zero initial condition given for transfer function system. "
"Internal conversion to state space used; may not be consistent "
"with given X0.")

sys = _convert_to_statespace(sys)
A, B, C, D = np.asarray(sys.A), np.asarray(sys.B), np.asarray(sys.C), \
np.asarray(sys.D)
Expand Down Expand Up @@ -358,12 +365,6 @@ def forced_response(sys, T=None, U=0., X0=0., transpose=False,
X0 = _check_convert_array(X0, [(n_states,), (n_states, 1)],
'Parameter ``X0``: ', squeeze=True)

# If we are passed a transfer function and X0 is non-zero, warn the user
if isinstance(sys, TransferFunction) and np.any(X0 != 0):
warnings.warn(
"Non-zero initial condition given for transfer function system. "
"Internal conversion to state space used; may not be consistent "
"with given X0.")

xout = np.zeros((n_states, n_steps))
xout[:, 0] = X0
Expand Down

0 comments on commit a09e98c

Please sign in to comment.