Equations of motion to state space

Converts set of equations of motion (symbolic format) into state space matrices (x_dot = A*x + B*u)
1.7K Downloads
Updated 18 Jan 2013

View License

This function evaluates any set of equations of motion and generates the state space matrices for the system. The equations must be in a structure where each equation is a new symbolic entry in the structure. States, the derivatives of the states, and the inputs must be cell arrays. The equations must be defined as symbolic statements (see examples for syntax). However, the parameters may be symbolic or numerical. If numerical, they must still be listed within a char string, but the solver will convert the final matrices from symbolic to real.

As many systems are not easily decoupled or the decoupled system equations are very large and difficult to evaluate, the function uses the mass, stiffness, input approach where:
M*x_dot = K*x + I *u
To convert to the more common x_dot = A*x + B*u, pre-divide by M: A = M\ K, B = M \ I.

If the parameters in the equations are symbolic, then only M, K, and I are returned. For numerical solution cases, A and B are also returned. For small(er) system (1 to 10 or so states), the user can usually calculate a symbolic A and B if needed. For larger systems, symbolic A and B matrices are generally not possible. This is the justification for using the M, K, I form.

The cost (run time) increases exponentially with the number of states as the solver uses a brute force approach where each equation is evaluated three times to separate the states, state derivatives, and inputs into the three matrices. As the solution matrices are developed using for loops (1 to number of states), one can understand how the cost grows rapidly. This approach is used even though there are more efficient approaches as it is guaranteed to manage any combination of states and derivatives. Even cases where higher order derivatives (2nd and up) exist.

The slower solution approach was acceptable as the system really only needs to be solved once. Unless the equations of motion are changing during the dynamic event, the state space model can be solved once off line and the symbolic M, K, and I matrices placed in the dynamic simulation to generate A and B matrices for time variant models. Only for cases where the system equations themselves change (mechanical components engaging, circuit switches engaging, etc.) would it be necessary to re-derive the state space matrices for each iteration. If that is the case, alternate solution methods might be better. However, for a small number of states (<5), the solver here might be fast enough to run inside the state solver.

Note: I have tried many eom forms and this solver works. If a formulation of the eoms is found that crashes the code, please send an example.

Cite As

michael arant (2024). Equations of motion to state space (https://www.mathworks.com/matlabcentral/fileexchange/39802-equations-of-motion-to-state-space), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.1.0.0

Added error check for improperly formatted equations of motion (state space form).

1.0.0.0