Skip to main content

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,

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

describes how the state changes at each instant. For a discrete-time system,

x[k+1]=fd(x[k],u[k],k)x[k+1]=f_d(x[k],u[k],k)

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 arcMain topicsWiki coverage
1Mathematical modeling, difference equations, population dynamicsMathematical Modeling
2Continuous-time systems, state variables, nonlinear elementsState Space, Nonlinear Systems
3Elementary numerical integrationNumerical Integration
4Linear systems, transfer functions, frequency response, zz-transformLinear Systems, Signals and Systems
5Simulink, algebraic loops, subsystems, discrete-time blocks, hybrid modelsSimulink Block Diagrams, Hybrid Systems
6Runge-Kutta, adaptive methods, multistep methods, stiffness, discontinuitiesStep Size and Stability
7Simulation tools, trimming, optimization, linearization, accelerationMATLAB Scripting, Nonlinear Linearization
8Advanced integration, dynamic errors, multirate, real-time simulationDiscrete-Time Systems, Validation Examples

Key results

The central simulation pipeline is

physical systemmathematical modelnumerical methodcomputed responseinterpretation.\text{physical system}\to\text{mathematical model}\to\text{numerical method}\to\text{computed response}\to\text{interpretation}.

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:

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

where pp denotes parameters. MATLAB solvers need a function that computes x˙\dot{x}. Simulink integrator diagrams need signals that compute each state derivative. Linear analysis needs matrices obtained from this form:

x˙=Ax+Bu,y=Cx+Du.\dot{x}=Ax+Bu, \qquad y=Cx+Du.

Numerical integration advances a solution from tkt_k to tk+1=tk+ht_{k+1}=t_k+h. Explicit Euler,

xk+1=xk+hf(tk,xk),x_{k+1}=x_k+h f(t_k,x_k),

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 orderPageMain deliverable
1This overviewMap of the simulation workflow
2Mathematical ModelingConservation laws and physical derivations
3State-Space RepresentationFirst-order vector form and matrices
4Numerical Integration MethodsEuler, trapezoidal, RK4, adaptive ideas
5Step Size, Accuracy, and StabilitySolver quality and convergence checks
6Linear SystemsPoles, modes, transfer functions, response
7Nonlinear SystemsNonlinear elements and Jacobian linearization
8MATLAB ScriptingReproducible script workflow
9Simulink Block DiagramsIntegrator diagrams, subsystems, algebraic loops
10Discrete-Time SystemsDifference equations and sampled-data models
11Hybrid SystemsEvents, modes, resets, hysteresis
12Validation ExamplesVerification, validation, and domain analogies

Worked example 1: Choose a simulation workflow for a tank model

Problem: A well-mixed tank obeys

Ah˙=qinhRh.A\dot{h}=q_\text{in}-\frac{h}{R_h}.

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.

  1. Identify the model type. The equation is a first-order continuous-time ODE with one state hh and one input qinq_\text{in}.

  2. Put it in state-space form:

h˙=1ARhh+1Aqin.\dot{h}=-\frac{1}{A R_h}h+\frac{1}{A}q_\text{in}.

This points to State-Space Representation.

  1. Choose a numerical method. If the tank is smooth and nonstiff, ode45 is 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.

  2. Predict the response. For constant inflow, the equilibrium is

hˉ=Rhqin.\bar{h}=R_h q_\text{in}.

The time constant is

τ=ARh.\tau=A R_h.

This gives an analytical check for the time-response plot.

  1. Build Simulink version. Use a Sum block for qinh/Rhq_\text{in}-h/R_h, a Gain 1/A1/A, and an Integrator for hh. This points to Simulink Block Diagrams.

  2. Verify. Compare MATLAB and Simulink outputs at the same input, initial condition, and solver settings. Then compare the final value with hˉ\bar{h}. This points to Validation Examples.

Checked answer: the correct response is a monotone exponential toward RhqinR_hq_\text{in}. 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

θ¨+bm2θ˙+gsinθ=1m2τ.\ddot{\theta}+\frac{b}{m\ell^2}\dot{\theta}+\frac{g}{\ell}\sin\theta=\frac{1}{m\ell^2}\tau.

You need a model for small oscillations near θ=0\theta=0, but later you may simulate large release angles. Decide which pages and methods apply.

  1. Convert to state variables:
x1=θ,x2=θ˙.x_1=\theta,\qquad x_2=\dot{\theta}.

Then

x˙1=x2,x˙2=bm2x2gsinx1+1m2τ.\begin{aligned} \dot{x}_1 &= x_2,\\ \dot{x}_2 &= -\frac{b}{m\ell^2}x_2-\frac{g}{\ell}\sin x_1+\frac{1}{m\ell^2}\tau. \end{aligned}
  1. For small oscillations, linearize sinx1\sin x_1 near zero:
sinx1x1.\sin x_1\approx x_1.
  1. The local linear model is
x˙=[01g/b/(m2)]x+[01/(m2)]τ.\dot{x}= \begin{bmatrix} 0 & 1\\ -g/\ell & -b/(m\ell^2) \end{bmatrix}x + \begin{bmatrix} 0\\ 1/(m\ell^2) \end{bmatrix}\tau.

This points to Nonlinear Systems and Linearization and Linear Systems.

  1. 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 bb.

  2. For large release angles, use the nonlinear sine model. The linear model underestimates period changes and can give wrong response for large θ\theta. This points back to MATLAB Scripting or Simulink Block Diagrams.

  3. Check both models. Run the nonlinear and linear simulations for 55^\circ and for 6060^\circ. 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