Ma · Mathematics

How to Write Coupled Nonlinear ODEs in State-Space Form

Published By the 9to5Science editorial team

At a glance

  1. 1. Choose the states

    Use enough variables to represent the system’s configuration and the derivatives needed to determine its future.

  2. 2. Make equations first order

    Introduce state variables for higher derivatives, such as velocity for each second-order position equation.

  3. 3. Collect the derivatives

    Write each state derivative as a function of the full state, the input, and, when needed, time.

  4. 4. Specify the output

    Define the measured or required output separately as a function of the state and input.

A state-space representation rewrites a system of differential equations as a set of first-order equations for a vector of state variables. For a nonlinear system, the standard form is

x˙=f(x,u,t),y=h(x,u,t),\dot{x}=f(x,u,t), \qquad y=h(x,u,t),

where xx is the state, uu is the input, and yy is the output. The equations may be coupled: the derivative of one state can depend on several other states. That dependence is included in the function ff.

What state-space form means

A state is a collection of variables that, together with the input and the system equations, determines how the system evolves from its current condition. If the model has no external input, write x˙=f(x,t)\dot{x}=f(x,t), or x˙=f(x)\dot{x}=f(x) when it is also time-independent (autonomous).

For a linear system, the state equation often has the form x˙=Ax+Bu\dot{x}=Ax+Bu. A general nonlinear system instead uses a possibly nonlinear function ff. You should not expect constant matrices AA and BB to represent it exactly. A nonlinear model can sometimes be approximated by a linear model near an equilibrium, but that is a separate step.

Convert higher-order equations to first order

If the original equations contain second derivatives, introduce a state for each position-like variable and another for its first derivative. More generally, introduce enough state variables to express the system using only first derivatives. Then solve the original equations for those derivatives and collect the resulting equations into a vector.

The state choices are not unique. A useful choice is one that makes the equations explicit, keeps the variables physically interpretable, and avoids unnecessary states. The number of states is often the number of independent initial conditions needed to determine a solution.

Worked example: two coupled nonlinear equations

Consider the system

q¨1+2q1+q1q2=u,q¨2+3q2−q12=0.\begin{aligned} \ddot{q}_1 + 2q_1 + q_1q_2 &= u,\\ \ddot{q}_2 + 3q_2 - q_1^2 &= 0. \end{aligned}

The terms q1q2q_1q_2 and q12q_1^2 make the equations nonlinear, and each equation involves a variable that also appears in the other equation. The input uu acts on the first equation.

Define positions and velocities as the states:

x1=q1,x2=q2,x3=q˙1,x4=q˙2.x_1=q_1,\qquad x_2=q_2,\qquad x_3=\dot{q}_1,\qquad x_4=\dot{q}_2.

The first two state derivatives follow directly from these definitions: x˙1=x3\dot{x}_1=x_3 and x˙2=x4\dot{x}_2=x_4. Rearranging the original equations gives

x˙3=q¨1=u−2q1−q1q2,x˙4=q¨2=−3q2+q12.\begin{aligned} \dot{x}_3 &= \ddot{q}_1 = u-2q_1-q_1q_2,\\ \dot{x}_4 &= \ddot{q}_2 = -3q_2+q_1^2. \end{aligned}

Substitute the state variables to obtain the state-space model:

x˙=[x3x4u−2x1−x1x2−3x2+x12],x=[x1x2x3x4].\dot{x}= \begin{bmatrix} x_3\\ x_4\\ u-2x_1-x_1x_2\\ -3x_2+x_1^2 \end{bmatrix}, \qquad x= \begin{bmatrix} x_1\\x_2\\x_3\\x_4 \end{bmatrix}.

If the output is the pair of positions, define y=[x1  x2]Ty=[x_1\;x_2]^T. If the output is only q1q_1, define y=x1y=x_1. The output equation depends on what you want to measure; it does not have to include every state.

When the equations are implicit

Some models are given in a form such as M(q)q¨=r(q,q˙,u,t)M(q)\ddot{q}=r(q,\dot{q},u,t). If the mass matrix M(q)M(q) is invertible at the conditions of interest, solve for acceleration:

q¨=M(q)−1r(q,q˙,u,t).\ddot{q}=M(q)^{-1}r(q,\dot{q},u,t).

Then take x=[qT  q˙T]Tx=[q^T\;\dot{q}^T]^T and write x˙=[q˙T  q¨T]T\dot{x}=[\dot{q}^T\;\ddot{q}^T]^T. If the matrix is singular, you may have a differential-algebraic system rather than an ordinary explicit state equation; it cannot necessarily be put into this form just by taking its inverse.

Common mistakes

  • Forgetting a velocity state: A second-order equation requires both a position and a velocity state for each independent coordinate.
  • Leaving derivatives on the right-hand side: Solve for the highest derivatives before writing the state equation.
  • Dropping cross-coupling: Keep terms involving other states, such as x1x2x_1x_2, in the appropriate derivative equation.
  • Calling the model linear because it is a vector equation: A vector form does not make the system linear. Products, powers, and nonlinear functions of states generally make ff nonlinear.
  • Confusing states with outputs: States describe the system’s internal condition; outputs are the quantities selected for measurement or reporting.

Check the result by substituting the state definitions back into each component equation. Each component of x˙\dot{x} must match the derivative of its corresponding state, and the reconstructed equations should agree with the original model.

References

  1. Nonlinear Systems, 3rd Edition — Hassan K. Khalil
  2. Applied Nonlinear Control — Jean-Jacques E. Slotine and Weiping Li

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.