Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make state, signal, event vectors/matrices more consistent to allow vectorization #21

Closed
ralfgerlich opened this issue Mar 25, 2021 · 0 comments
Labels
api change Compatibility-breaking API change enhancement New feature or request
Milestone

Comments

@ralfgerlich
Copy link
Member

ralfgerlich commented Mar 25, 2021

In simulation, simple vectors are used to represent all states, signals and event values. In the simulation results, they are represented as matrices, with the row being the time-axis and the column being the state/signal/event axis. This is inconsistent, e.g., with the matrix algebra for LTI, and also makes vectorization of state derivative, signal and event functions more difficult.

For an LTI, the state derivative is represented as A x(t) + B u(t) , with the state x(t) and the input u(t). Thus, both the state and the input are expected to be column vectors. Considering a time series -- such as the result of a simulation -- it is most natural to represent the values of state and inputs at different times as columns of matrices X and U, so that the matrix of state derivatives would naturally be A X + B U.

Similarly, linear outputs can be represented as y(t) = C x(t) + D u(t), and for a time series, Y = C X + D U would still hold. The structure of the formula -- and the code representing the formula -- would not have to change.

NumPy supports vectorization and broadcasting in that manner, and, for example, most of the ODE solvers provided by SciPy also do. If we were to consistently represent state and input vectors as column vectors, we could make use of these features by default without any code-changes on the state derivative, signal and event functions being necessary.

Vectorization would be the default then, and for any function not vectorizable for any reason, the numpy.vectorize function could be used as an adaptor.

This would mostly require changes to the SimulatorResult class, but also would allow us to simplify the linearization implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api change Compatibility-breaking API change enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant