Choose States and Build a Matrix Model

English translation

Control Engineering I · Week 5

This week's objective · Convert a differential equation of order 2 into two differential equations of order 1.

Run: After signing in to MathWorks, open .mlx in your workspace. Click inside the code → Live Editor → Run Section to run one section at a time. Run runs everything. After changing a value, rerun the relevant section. Edit the text in ⟦enter here⟧ response fields; do not execute them. You can use Ctrl+Enter on Windows/Linux and ⌘+Enter on Mac.

From constant-acceleration motion to state space

For constant-acceleration motion, knowing current position, velocity, and constant acceleration let us find later positions. Now consider a spring and damper that cause acceleration to change during motion.

Two objects at the same position will have different later positions if one is stationary and the other is moving. Current position alone cannot determine the future; current velocity is also needed.

Rearranging the force relation established in week 2 for acceleration gives the following. yy is position from equilibrium, vv is velocity, and uu is the applied force.

Mÿ=u−bẏ−ky⇒ẏ=v,v̇=u−bv−kyMM\ddot y=u-b\dot y-ky \quad\Longrightarrow\quad \dot y=v,\qquad \dot v=\frac{u-bv-ky}{M}

  • First equation: current velocity determines the rate of change of position.
  • Second equation: current position, velocity, and applied force determine the rate of change of velocity.

Thus, given the model and subsequent input, knowing the current position and velocity lets us calculate how both change together. Choose these two quantities as the states in this model.

𝒙=[yv],𝒙̇=[v(u−bv−ky)/M]\mathbf{x}=\begin{bmatrix}y\\v\end{bmatrix},\qquad \dot{\mathbf{x}}=\begin{bmatrix}v\\(u-bv-ky)/M\end{bmatrix}

This rewrites the 2nd-order differential equation for position as two 1st-order differential equations for position and velocity. Acceleration is calculated from these states and the input, so it is not added as a separate state. Here, M,b,kM,b,k represents fixed parameters describing the device.

Which of position, velocity, and acceleration are already known?
Condition Current information needed to predict position
Velocity is known in advance and remains constant Current position
Acceleration is known and constant Current position and velocity
The spring–damper model and subsequent force are given Current position and velocity. Calculate acceleration from the model

Simplification makes the change relations easier to work with but does not necessarily reduce the number of states. Unlike motion at a known constant velocity, constant-acceleration motion requires the current velocity to be updated continually.

Position in physical space and a point in state space

The cart moves along a straight line in physical space. In state space, current state can be represented by a point with position on the horizontal axis and velocity on the vertical axis. Equal positions with different velocities give different points. Over time, the point traces a curve, but following a single curve does not determine the dimension of the state space.

In the exercise, initial state [0;1] starts at the reference position with velocity 1, while [1;0] starts at position 1 at rest. Different starting information produces different responses even for the same model. Compare the two results, then relate them to the matrix representation below.

1. A state provides information for calculating the next moment

Number the position and velocity chosen above and organize them into matrices. Setting x1=y,x2=ẏx_1=y,\ x_2=\dot y gives ẋ1=x2\dot x_1=x_2 and ẋ2=−kMx1−bMx2+uM\dot x_2=-\frac{k}{M}x_1-\frac{b}{M}x_2+\frac{u}{M}.

A state provides information for calculating the next moment

States and outputs may differ. Choosing position as the output gives C=[1,0]C=[1,0], while choosing velocity gives C=[0,1]C=[0,1]. The system's internal dynamics A remain unchanged.

2. Check the dimensions of A, B, C, and D

With n states, m inputs, and p outputs, A is n×n, B is n×m, C is p×n, and D is p×m. Compare the dimensions of each product in 𝐱̇=A𝐱+Bu\dot{\mathbf x}=A\mathbf x+B u and y=C𝐱+Duy=C\mathbf x+D u.

Check the dimensions of A, B, C, and D

Standard linear state space represents LTI models. Constant A,B,C,D matrices cannot exactly represent every nonlinear system.

3. Read the RLC connection structure first

This electrical exercise models a current source supplying a capacitor and a series RL branch. The states are capacitor voltage and inductor current, and the output is resistor voltage R iLi_L. Distinguish it from the output of the parallel RLC circuit in Week 2.

Read the RLC connection structure first

KCL gives Ccap·vC′=u−iL, and the series RL branch gives L·iL′=vC−R·iL. Thus, for x=[vC;iLi_L], A's first row is [0,−1/Ccap] and its second is [1/L,−R/L]. This circuit has a capacitor branch in parallel with a series R–L branch.

Use distinct names: Ccap for capacitance and Cout for the output matrix. Reusing C for both can cause errors when changing a parameter and rerunning.

4. Rebuild the model after changing parameters

Run the baseline model with M=1,b=2,k=5, then compare b=0.5 and 10. For the electrical model, start with R=3,L=1,Ccap=0.5, then compare R=1 and 10. Recreate A,B,C,D and ss using the changed values.

Rebuild the model after changing parameters

When the mechanical model stops under a constant 1 N force, spring force k·y equals 1 N, giving final displacement 1/k. For the electrical model with a sustained 1 A current, check whether resistor voltage converges to R to verify the output definition.

Check your understanding

  1. What values should go into the code, and what does each row and column of the resulting array represent? If calculating physical quantities, have you also checked the units?
  2. Can you identify which parts to rerun when you change one condition?
  3. Do the results match your expectations? If they differ, can you explain why using the output values or plots?

Official MATLAB documentation · Control System Toolbox

Practice materials