Simulation of Dynamic Systems
Simulation of dynamic systems studies how mathematical models evolve over time when they are solved on a computer. In the setting of Klee and Allen's Simulation of Dynamic Systems with MATLAB and Simulink, the main focus is continuous system simulation: physical, biological, and engineered systems represented by algebraic equations, ordinary differential equations, difference equations, and block diagrams.
These notes are written as working study pages. They emphasize model derivation, state-space form, numerical integration, MATLAB scripts, Simulink implementation, time-response interpretation, and verification. The goal is not to replace a textbook or software manual, but to give a coherent path from physical assumptions to a simulation result that can be checked, explained, and improved.
Definitions
A dynamic system is a system whose current behavior depends on stored information from the past. The stored information is represented by state variables. For a continuous-time system,
describes how the state changes at each instant. For a discrete-time system,
describes how the state updates from one sample to the next.
A model is a simplified mathematical representation of a real or proposed system. A simulation is the execution of that model over time. The distinction matters: a model can be physically wrong even if simulated perfectly, and a correct model can be simulated poorly with an unsuitable solver or step size.
MATLAB is useful for scripted simulations, parameter sweeps, numerical integration, plotting, and analysis. Simulink is useful for executable block diagrams, subsystem composition, hybrid continuous/discrete models, and workflows where signal flow is clearer than code. The two tools are complementary: the same state equations can often be implemented as a MATLAB derivative function or as Simulink blocks.
The source text's table of contents follows this broad sequence:
| Book arc | Main topics | Wiki coverage |
|---|---|---|
| 1 | Mathematical modeling, difference equations, population dynamics | Mathematical Modeling |
| 2 | Continuous-time systems, state variables, nonlinear elements | State Space, Nonlinear Systems |
| 3 | Elementary numerical integration | Numerical Integration |
| 4 | Linear systems, transfer functions, frequency response, -transform | Linear Systems, Signals and Systems |
| 5 | Simulink, algebraic loops, subsystems, discrete-time blocks, hybrid models | Simulink Block Diagrams, Hybrid Systems |
| 6 | Runge-Kutta, adaptive methods, multistep methods, stiffness, discontinuities | Step Size and Stability |
| 7 | Simulation tools, trimming, optimization, linearization, acceleration | MATLAB Scripting, Nonlinear Linearization |
| 8 | Advanced integration, dynamic errors, multirate, real-time simulation | Discrete-Time Systems, Validation Examples |
Key results
The central simulation pipeline is
Every arrow can introduce error. Modeling error enters when assumptions omit important physics. Numerical error enters when the solver and step size approximate the equations. Implementation error enters when code or block diagrams do not match the equations. Interpretation error enters when plots are read without checking units, initial conditions, solver settings, or validation data.
State-space form is the common interface:
where denotes parameters. MATLAB solvers need a function that computes . Simulink integrator diagrams need signals that compute each state derivative. Linear analysis needs matrices obtained from this form:
Numerical integration advances a solution from to . Explicit Euler,
is simple but low accuracy and conditionally stable. Runge-Kutta methods use staged slopes for higher accuracy. Adaptive solvers estimate error and adjust step size. Stiff solvers handle systems where fast stable modes restrict explicit methods.
The result of a simulation should be checked against at least one anchor: an equilibrium, an analytical solution, a limiting case, a conservation law, a refined-step solution, a frequency-domain prediction, or measured data. This verification habit is the difference between making a plot and doing simulation engineering.
Visual
| Page order | Page | Main deliverable |
|---|---|---|
| 1 | This overview | Map of the simulation workflow |
| 2 | Mathematical Modeling | Conservation laws and physical derivations |
| 3 | State-Space Representation | First-order vector form and matrices |
| 4 | Numerical Integration Methods | Euler, trapezoidal, RK4, adaptive ideas |
| 5 | Step Size, Accuracy, and Stability | Solver quality and convergence checks |
| 6 | Linear Systems | Poles, modes, transfer functions, response |
| 7 | Nonlinear Systems | Nonlinear elements and Jacobian linearization |
| 8 | MATLAB Scripting | Reproducible script workflow |
| 9 | Simulink Block Diagrams | Integrator diagrams, subsystems, algebraic loops |
| 10 | Discrete-Time Systems | Difference equations and sampled-data models |
| 11 | Hybrid Systems | Events, modes, resets, hysteresis |
| 12 | Validation Examples | Verification, validation, and domain analogies |
Worked example 1: Choose a simulation workflow for a tank model
Problem: A well-mixed tank obeys
You need to predict the height response to a change in inflow, compare MATLAB and Simulink implementations, and decide what pages in this section to use.
-
Identify the model type. The equation is a first-order continuous-time ODE with one state and one input .
-
Put it in state-space form:
This points to State-Space Representation.
-
Choose a numerical method. If the tank is smooth and nonstiff,
ode45is a reasonable MATLAB default. If using a fixed-step teaching loop, explicit Euler or RK4 can demonstrate the effect of step size. This points to Numerical Integration Methods. -
Predict the response. For constant inflow, the equilibrium is
The time constant is
This gives an analytical check for the time-response plot.
-
Build Simulink version. Use a Sum block for , a Gain , and an Integrator for . This points to Simulink Block Diagrams.
-
Verify. Compare MATLAB and Simulink outputs at the same input, initial condition, and solver settings. Then compare the final value with . This points to Validation Examples.
Checked answer: the correct response is a monotone exponential toward . If MATLAB and Simulink disagree, the likely causes are different initial conditions, solver settings, input timing, or block signs.
Worked example 2: Decide when linear analysis is enough
Problem: A pendulum model is
You need a model for small oscillations near , but later you may simulate large release angles. Decide which pages and methods apply.
- Convert to state variables:
Then
- For small oscillations, linearize near zero:
- The local linear model is
This points to Nonlinear Systems and Linearization and Linear Systems.
-
Predict small-angle behavior. If damping is positive, the eigenvalues should have negative real parts, so the time response should be stable and oscillatory or overdamped depending on .
-
For large release angles, use the nonlinear sine model. The linear model underestimates period changes and can give wrong response for large . This points back to MATLAB Scripting or Simulink Block Diagrams.
-
Check both models. Run the nonlinear and linear simulations for and for . The small-angle plots should agree closely; the large-angle plots should diverge.
Checked answer: linear analysis is enough for local small-signal behavior near the downward equilibrium, but nonlinear simulation is required for large motion or switching constraints. The difference should be visible in the time-response plot as angle grows.
Code
clear; clc; close all;
% Overview example: compare nonlinear and linear pendulum models.
m = 1;
ell = 1;
b = 0.08;
g = 9.81;
A = [0 1; -g/ell -b/(m*ell^2)];
pend_linear = @(t,x) A*x;
pend_nonlinear = @(t,x) [x(2); ...
-(b/(m*ell^2))*x(2) - (g/ell)*sin(x(1))];
angles = [5 60]*pi/180;
figure;
for i = 1:numel(angles)
x0 = [angles(i); 0];
[tn, xn] = ode45(pend_nonlinear, [0 10], x0);
[tl, xl] = ode45(pend_linear, [0 10], x0);
subplot(2,1,i);
plot(tn, xn(:,1), 'b-', tl, xl(:,1), 'r--', 'LineWidth', 1.3);
grid on;
ylabel('\theta (rad)');
title(sprintf('Initial angle = %.0f degrees', angles(i)*180/pi));
legend('Nonlinear', 'Linearized', 'Location', 'best');
end
xlabel('Time (s)');
The first subplot should show close agreement between nonlinear and linear models. The second should show visible mismatch because the sine nonlinearity matters. A Simulink version uses two parallel subsystems, one with a Trigonometric Function block and one with a State-Space block, feeding a common Scope for comparison.
Common pitfalls
- Treating simulation as a substitute for deriving and checking the model.
- Building a Simulink diagram before deciding what the states are.
- Accepting a time plot without checking equilibrium, units, or solver settings.
- Using a linearized model outside its operating region.
- Confusing discrete controller sample time with numerical solver step size.
- Reporting validation without independent data or an explicit quantity of interest.
Connections
- Mathematical Modeling of Continuous-Time Systems
- State-Space Representation
- Numerical Integration Methods
- Step Size, Accuracy, and Stability
- Linear Systems, Transfer Functions, and Modes
- Nonlinear Systems and Linearization
- MATLAB Scripting for Simulation
- Simulink Block Diagrams
- Discrete-Time and Sampled-Data Systems
- Hybrid Systems and Event Handling
- Validation and Multi-Domain Simulation Examples