Skip to content

t_eval is not respected for system with 0 states #742

@hyumo

Description

@hyumo

It seems that t_eval is ignored when simulating a system with nstates=0.

The bug seems to be located at:

if nstates == 0:
# No states => map input to output
u = U[0] if len(U.shape) == 1 else U[:, 0]
y = np.zeros((np.shape(sys._out(T[0], X0, u))[0], len(T)))
for i in range(len(T)):
u = U[i] if len(U.shape) == 1 else U[:, i]
y[:, i] = sys._out(T[i], [], u)
return TimeResponseData(
T, y, None, U, issiso=sys.issiso(),
output_labels=sys.output_index, input_labels=sys.input_index,
transpose=transpose, return_x=return_x, squeeze=squeeze)

Instead, the following lines are expected to be used, I think:

def ufun(t):
# Find the value of the index using linear interpolation
# Use clip to allow for extrapolation if t is out of range
idx = np.clip(np.searchsorted(T, t, side='left'), 1, len(T)-1)
dt = (t - T[idx-1]) / (T[idx] - T[idx-1])
return U[..., idx-1] * (1. - dt) + U[..., idx] * dt
# Check to make sure this is not a static function
if nstates == 0: # No states => map input to output
# Make sure the user gave a time vector for evaluation (or 'T')
if t_eval is None:
# User overrode t_eval with None, but didn't give us the times...
warn("t_eval set to None, but no dynamics; using T instead")
t_eval = T
# Allocate space for the inputs and outputs
u = np.zeros((ninputs, len(t_eval)))
y = np.zeros((noutputs, len(t_eval)))
# Compute the input and output at each point in time
for i, t in enumerate(t_eval):
u[:, i] = ufun(t)
y[:, i] = sys._out(t, [], u[:, i])
return TimeResponseData(
t_eval, y, None, u, issiso=sys.issiso(),
output_labels=sys.output_index, input_labels=sys.input_index,
transpose=transpose, return_x=return_x, squeeze=squeeze)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy