| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → SimMechanics |
| Contents | Index |
| Learn more about SimMechanics |
| On this page… |
|---|
About Linearization and SimMechanics Software |
The Simulink linmod command creates linear time-invariant (LTI) state-space models from Simulink models. It linearizes each block separately. You can use this command to generate an LTI state-space model from a SimMechanics model, for example, to serve as input to Control System Toolbox™ commands that generate controller models. The linmod command allows you to specify the point in state space about which it linearizes the model (the operating point). You should choose a point where your model is in equilibrium, i.e., where the net force on the model is zero. You can use the Simulink trim command to find a suitable operating point (see Trimming Mechanical Models in this chapter). By default, linmod uses an adaptive perturbation method to linearize model. The Machine Environment dialog allows you to require that linmod use a fixed perturbation method instead (see Choosing an Analysis Mode in the Running Mechanical Models chapter). The examples then following illustrate the use of linmod to linearize SimMechanics models.
Consult the Simulink documentation for more on Linearizing Models. You can also enter help linmod at the MATLAB command line.
There are restrictions on how you linearize mechanical models.
If you specify any joint primitive initial conditions with Joint Initial Condition Actuator blocks, these initial condition values always override any state vector initial values specified via the linmod command.
Joint primitives with JICA blocks are preferentially chosen for the set of independent states in linearization.
Avoid incorporating discrete events or motion discontinuities in a linearized model. If you include event- or discontinuity-triggering blocks, ensure that the machine does not induce discontinuities as it moves through the linearized regime you are modeling.
Use of Joint Stiction Actuator blocks in a linearized model causes an error.
Because closed loops impose constraints on states, you cannot linearize a closed-loop SimMechanics model with the linmod2 command.
SimMechanics linearization uses only the acceleration as an independent motion actuation input because it is equivalent to a force or torque. A similar restriction holds for model trimming; see Trimming in the Presence of Motion Actuation preceding. As a consequence, the only motion actuation signal that can be set as a model input is the acceleration signal.
If you want to linearize a SimMechanics model containing motion actuators, you must
Make the velocity and position/angle parts of the motion actuation signal dependent only on the acceleration signal
Make the velocity and position/angle consistent with the acceleration part by use of Integrator blocks. A motion actuation signal is a vector with components ordered as position/angle, velocity, and acceleration, respectively.
This technique is recommended in Stabilizing Numerical Derivatives in Actuator Signals in the Modeling Mechanical Systems chapter. It is required here.
SimMechanics linearization uses only the acceleration as an independent motion actuation input because it is equivalent to a force or torque. As a consequence, only the acceleration signal can be used as an independent motion actuation input.
A similar restriction holds for model trimming; see Trimming in the Presence of Motion Actuation preceding.
Motion Actuation as a Model Input for Linearization

Linearizing in the Presence of Motion Actuation. You can put your model input port in another part of your model, then feed that input as an acceleration into a motion actuator with a Simulink signal line. You must still derive the velocity and position/angle motion actuation signals in the same way: by integrating whatever signal you use for acceleration once and twice, respectively.
Consider a double pendulum initially hanging straight up and down.

The net force on the pendulum is zero in this configuration. The pendulum is thus in equilibrium.
Open the mech_dpend_forw model.

To linearize this model, enter
[A B C D] = linmod('mech_dpend_forw');at the MATLAB command line. This form of the linmod command linearizes the model about the model's initial state.
Note Joint initial conditions specified with IC blocks always override any state vector initial values passed to the linmod command. The double pendulum model in this example contains no IC blocks. The initial conditions specified with the linmod command are therefore implemented without modification. |
The matrices A, B, C, D returned by the linmod command correspond to the standard mathematical representation of an LTI state-space model:
![]()
where x is the model's state vector, y is its outputs, and u is its inputs. The double pendulum model has no inputs or outputs. Consequently, only A is not null. This reduces the state-space model for the double pendulum to
![]()
where
A =
0 0 1.0000 0
0 0 0 1.0000
-137.3400 39.2400 0 0
39.2400 -19.6200 0 0This model specifies the relationship between the state derivatives and the states of the double pendulum. The state vector of the LTI model has the same format as the state vector of the SimMechanics model. The SimMechanics mech_stateVectorMgr command gives the format of the state vector as follows:
StateManager = mech_stateVectorMgr('mech_dpend_forw/G');
StateManager.StateNames
ans =
'mech_dpend_forw/J2:R1:Position'
'mech_dpend_forw/J1:R1:Position'
'mech_dpend_forw/J2:R1:Velocity'
'mech_dpend_forw/J1:R1:Velocity'Right-multiplying A by the state vector x yields the differential state equations corresponding to the LTI model of the double pendulum,
![]()
where
![]()
The array of coefficients on the right-hand side of the differential equations represents a matrix of squared frequencies. The eigenvalues of this matrix are the squared frequencies of the system's response modes. These modes characterize how the double pendulum responds to small perturbations in the vicinity of the operating point, which here is the force-free equilibrium.
The following Simulink model implements the state-space model represented by these equations.

This model in turn allows creation of a model located in mech_dpend_lin that computes the LTI approximation error.

Running the model twice with the upper joint deflected 2 degrees and 5 degrees, respectively, shows an increase in error as the initial state of the system strays from the pendulum's equilibrium position and as time elapses. This is the expected behavior of a linear state-space approximation.

Control System Toolbox Function This section uses the Control System Toolbox function minreal. Refer to the Control System Toolbox user's guide for more about this function and state-space analysis. |
Linearizing a closed-loop machine is more complex than open-topology analysis. Each closed loop in the machine imposes implicit constraints that render some of the degrees of freedom (DoFs) dependent. Linearization of such a system must recognize that not all the DoFs are independent. A straightforward implementation of the linmod command results in redundant system states. You can eliminate these with the minreal function, which finds the minimal state space needed to represent your linearized model. To ensure that minreal produces a nonnull state space, you must linearize a closed-loop machine with at least one input u and one output y.
mech_four_bar_lin illustrates this reduction of independent DoFs: of the four revolute joints, only one is an independent DoF, which can be taken as any one of the revolutes. This model defines workspace variables in order to configure the initial geometry of lengths and angles (expressed in the model in meters and radians, respectively). Run the model in Forward Dynamics mode.

Consider a strategy to linearize the model about the four bar's (stable) natural equilibrium. You first find the natural equilibrium configuration, which is best accomplished by analyzing the loop constraints, making a guess, and then using the trim command to determine the equilibrium exactly. After choosing a system input and output, you then linearize the system.
The Modeling, Simulating, and Visualizing Simple Machines chapter presents this system in detail, in the section Creating a Closed-Loop Mechanical Model. The preceding sections of this chapter, Inverse Dynamics Mode with a Double Pendulum and Constrained Trimming of a Four Bar Machine, discuss the inverse dynamics and trimming of the four bar system.
You can determine the constraints and independent DoFs of the four bar with geometric and trigonometric identities applied to its quadrilateral shape. The lengths of the bars are l1, l2, and l3, with the fixed base having length l4.

The four joint angles satisfy α + β + γ + δ = 2π. Imagine cutting the quadrilateral diagonally from the α to the γ vertices, then from the β to the δ vertices. The law of cosines applied to these diagonals and the triangles so formed results in two constraints:
l12 + l22 - 2l1l2cosγ = l32 + l42 - 2l3l4cosα
l22 + l32 - 2l2l3cosβ = l12 + l42 - 2l1l4cosδ
The four angles are thus subject to three constraints. Choose α (the crank angle) as the independent DoF. You can determine β, γ, and δ from α by inverting the constraints.
First guess the natural equilibrium. An obvious guess for the natural equilibrium is for the crank (Bar 3) to point straight down, α = -90o.
Use the quadrilateral constraints to find
β = 313.2o, γ = 60.3o, and δ = 76.5o
Redefine the workspace angles to these values (converted to radians).
alpha = -90*pi/180; beta = 313.2*pi/180; gamma = 60.3*pi/180; delta = 76.5*pi/180; beta2 = pi - gamma - delta; delta2 = pi - delta;
Update the diagram and run the model again. This configuration is not the natural equilibrium, but it is close.
Now find the natural equilibrium exactly by trimming the four bar in a manner similar to Constrained Trimming of a Four Bar Machine in this chapter, but without external torque actuation. Revolute1 is already manually configured to be the cut joint in the closed loop, ensuring the DoF represented by Revolute4 is not eliminated from state space when the loop is cut.
Set the analysis mode to Trimming. Trimming mode inserts a subsystem and an output block that outputs a four-component signal representing the mechanical constraints resulting from the closed loop.
Use mech_stateVectorMgr to obtain the system's state vector:
StateManager = ...
mech_stateVectorMgr('mech_four_bar_lin/Ground_2');
StateManager.StateNames
ans =
'mech_four_bar_lin/Revolute2:R1:Position'
'mech_four_bar_lin/Revolute3:R1:Position'
'mech_four_bar_lin/Revolute4:R1:Position'
'mech_four_bar_lin/Revolute2:R1:Velocity'
'mech_four_bar_lin/Revolute3:R1:Velocity'
'mech_four_bar_lin/Revolute4:R1:Velocity'Revolute1 is the cut joint and is missing from the list. States 1, 2, and 3 are the revolute 2, 3, and 4 angles, respectively; while states 4, 5, and 6 are the revolute 2, 3, and 4 angular velocities, respectively.
Set up the necessary trimming vectors:
x0 = [0;0;0;0;0;0]; ix = []; u0 = []; iu = []; y0 = [0;0;0;0]; iy = [1;2;3;4]; dx0 = [0;0;0;0;0;0]; idx = [3;6];
The x0 vector tells the trim command to start its search for the equilibrium with the four bar in its initial configuration (the equilibrium guess you entered into the workspace previously) and with zero angular velocities. The index vector ix sets the states that, in the actual equilibrium, should keep the values specified in x0. Here there are none.
The u0 and iu vectors specify system inputs, but there are none.
The y0 vector sets the initial values of the constraint outputs to zero. The index vector iy requires that the constraint outputs at equilibrium be equal to their initial values (0). This ensures that the solution satisfies the mechanical constraints.
The dx0 vector specifies the initial state derivatives. The initial derivatives of the angles (i.e., the angular velocities) and of the angular velocities (i.e., the angular accelerations) are set to zero. The index vector idx specifies that the velocity and acceleration of Revolute4 in the natural equilibrium must vanish. It is not necessary to constrain the derivatives of the other states because the system has only one independent DoF.
[x,u,y,dx] = ...
trim('mech_four_bar_lin',x0,u0,y0,ix,iu,iy,dx0,idx);The u vector is empty. The components of y and dx vanish, within tolerances, indicating that in equilibrium, respectively, the mechanical constraints are satisfied and the state derivatives vanish. The last three components of x vanish, indicating zero angular velocities at equilibrium. The first three components of x represent the natural equilibrium angles (in radians), measured as deviations from the initial configuration. The Revolute4 angle is -0.2395 rad = -13.7o from the starting point.
From x, you can calculate all the angle values. The natural equilibrium is αeq = -90o - 13.7o = -103.7o, βeq = 310.1o + 13.0o = 323.1o, γeq = 60.3o + 2.5o = 62.8o, and δeq = 360o - αeq - βeq - γeq = 74.7o.
You can now linearize the system at this trim point.
Reset the angles in your workspace to the natural equilibrium point:
alpha = alpha + x(3); beta = beta + x(2); gamma = gamma + x(1); delta = 2*pi - alpha - beta - gamma; beta2 = pi - gamma - delta; delta2 = pi - delta;
Change the analysis mode back to Forward Dynamics and update the diagram. Run the model to check that the mechanism indeed does not move.
To obtain a nontrivial linearized model, you need at least one input and one output. Connect a Joint Actuator to Revolute4 to actuate it with a torque. Then insert Simulink Inport and Outport blocks to input the torque and measure the angular velocity.

Set the input torque to zero and the initial state to the model's initial configuration, the natural equilibrium:
u = 0; x = [0;0;0;0;0;0];
Linearize the model and use minreal to eliminate the redundant states:
[A,B,C,D] = linmod('mech_four_bar_lin',x,u);
[a,b,c,d] = minreal(A,B,C,D);leaving two states, α and dα/dt. The component a(2,1) = -80.1 < 0, indicating that this natural equilibrium is stable. The linearized motion is governed by d2α/dt2 = a(2,1)*α.
See Open-Topology Linearization: Double Pendulum preceding for more about the linearized state space representation.
![]() | Trimming Mechanical Models | Motion, Control, and Real-Time Simulation | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |