0% found this document useful (0 votes)
6 views16 pages

State Space Models MATLAB

The document provides a comprehensive guide on State-Space Models in MATLAB, detailing their mathematical framework and real-life engineering applications. It outlines a systematic four-step process for modeling dynamic systems, including deriving differential equations, selecting state variables, formulating state-space equations, and implementing them in MATLAB. Three specific engineering problems are explored: a car suspension system, an RLC circuit for radio tuning, and a room heating system, each demonstrating the practical application of state-space modeling techniques.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views16 pages

State Space Models MATLAB

The document provides a comprehensive guide on State-Space Models in MATLAB, detailing their mathematical framework and real-life engineering applications. It outlines a systematic four-step process for modeling dynamic systems, including deriving differential equations, selecting state variables, formulating state-space equations, and implementing them in MATLAB. Three specific engineering problems are explored: a car suspension system, an RLC circuit for radio tuning, and a room heating system, each demonstrating the practical application of state-space modeling techniques.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

State-Space Models in MATLAB — Real-Life Engineering Applications

STATE-SPACE MODELS IN MATLAB


Real-Life Engineering Applications
A Complete Step-by-Step Reference Guide

What is a State-Space Model?


A State-Space Model is a mathematical framework used in control engineering and systems theory to
describe the behavior of a dynamic system through a set of first-order differential equations. Instead of
working with higher-order differential equations, we convert them into a compact matrix form that is
both easy to simulate and easy to analyze.

The standard continuous-time state-space representation uses two fundamental equations:

State Equation: x'(t) = A·x(t) + B·u(t)


Output Equation: y(t) = C·x(t) + D·u(t)

Where the matrices and vectors have the following meanings:


• x(t) = State vector — the internal variables that capture the system's memory or current
condition
• u(t) = Input vector — the external forces, voltages, flows, or signals driving the system
• y(t) = Output vector — the measurable quantities we observe or wish to control
• A = System matrix — governs how the states evolve on their own
• B = Input matrix — maps the input into the state equations
• C = Output matrix — maps the states to the output
• D = Feedthrough matrix — direct connection from input to output (often zero)

The Systematic 4-Step Process


To solve any real-life problem using State-Space Models in MATLAB, we follow four clear and
repeatable steps:

• Step 1 — Mathematical Modeling: Derive the governing Differential Equation from Newton's
Laws, Kirchhoff's Laws, thermodynamic balance, fluid mechanics, or any physical law that
applies to the system.
• Step 2 — State Variable Selection: Choose a minimal set of variables that, together with the
input, fully describe the future behavior of the system. Typically, these are physical quantities
like position and velocity, or charge and current.
• Step 3 — State-Space Equations: Rewrite the differential equations in first-order form and
arrange them into the standard matrix equations x' = Ax + Bu and y = Cx + Du.

Page 1 of 16
State-Space Models in MATLAB — Real-Life Engineering Applications

• Step 4 — MATLAB Implementation: Enter the A, B, C, D matrices into MATLAB using the ss()
command, then use simulation tools such as step(), impulse(), lsim(), or plot() to analyze and
visualize the system's response.

Problem 1: Mechanical System — Mass-Spring-Damper (Car


Suspension)

1.1 Real-Life Context and Motivation


Every vehicle on the road must handle uneven surfaces — potholes, speed bumps, gravel roads, and
highway joints. When a car's wheel hits a bump, an impulsive force is applied to the suspension
system. Without proper engineering, this force would be transmitted directly to the car body and
passengers, causing discomfort, loss of vehicle control, and structural fatigue.

The suspension system consists of three fundamental mechanical components working together:
• A mass (m): Represents the car body's mass being supported — typically a quarter of the
vehicle's total mass is used in a 'quarter-car model'.
• A spring (k): Stores and releases energy, supporting the car's weight and providing restoring
force proportional to displacement.
• A damper or shock absorber (c): Dissipates energy by converting mechanical motion into heat,
preventing the car from bouncing endlessly.

Engineering Goal: Design the suspension so the car body returns to equilibrium quickly after a
bump, without excessive oscillation or discomfort to passengers.

1.2 Step 1 — Deriving the Differential Equation


We apply Newton's Second Law of Motion: the net force acting on the mass equals the mass times its
acceleration. Taking downward as positive and measuring displacement y from the equilibrium position:

Forces acting on the car body mass m:


• Applied external force: F(t) — force from road bump
• Spring force (restorative): -k·y — opposes displacement
• Damping force (resistive): -c·(dy/dt) — opposes velocity

Newton's 2nd Law: m·(d²y/dt²) = F(t) - k·y - c·(dy/dt)


Rearranged: m·ÿ + c·ẏ + k·y = F(t)

This is a 2nd-order linear ordinary differential equation (ODE). It cannot be directly entered into
MATLAB as-is. We must convert it to state-space form.

Page 2 of 16
State-Space Models in MATLAB — Real-Life Engineering Applications

1.3 Step 2 — Selecting State Variables


Since the differential equation is 2nd order, we need exactly 2 state variables. The standard choice is
the two quantities that appear in the equation and carry physical meaning:

x₁ = y (displacement — position of car body)


x₂ = ẏ = dy/dt (velocity — rate of change of displacement)

These two variables together completely describe the state of the suspension system at any instant in
time. Knowing x₁ and x₂ at time t₀, and knowing the future input F(t), allows us to predict the entire
future behavior.

1.4 Step 3 — Writing the State-Space Equations


We now write the first-order equations for the derivatives of each state variable:

ẋ₁ = x₂
ẋ₂ = -(k/m)·x₁ - (c/m)·x₂ + (1/m)·F

For the output, we observe the displacement (position):


y = x₁

In standard matrix form x' = Ax + Bu and y = Cx + Du:

A [ 0, 1 ] [ -k/m, -c/m ]
B [ 0 ] [ 1/m ]
C [ 1, 0 ]
D [ 0 ]

1.5 Step 4 — MATLAB Implementation


We use typical car suspension parameter values: mass m = 1000 kg (quarter car), spring stiffness k =
15000 N/m, and damping coefficient c = 1500 N·s/m. The system is analyzed under a unit step force
input (simulating a sudden bump).

Complete MATLAB Code:

% ============================================================
% Problem 1: Mass-Spring-Damper (Car Suspension)
% State-Space Model in MATLAB
% ============================================================

% --- System Parameters ---

Page 3 of 16
State-Space Models in MATLAB — Real-Life Engineering Applications

m = 1000; % Mass of car body (kg)


k = 15000; % Spring stiffness (N/m)
c = 1500; % Damping coefficient (N.s/m)

% --- State-Space Matrices ---


A = [0, 1;
-k/m, -c/m];

B = [0;
1/m];

C = [1, 0]; % Output: displacement y = x1

D = [0];

% --- Create State-Space System Object ---


sys = ss(A, B, C, D);

% --- Simulation: Step Response (bump input) ---


t = 0:0.01:10; % Time vector: 0 to 10 seconds
F = ones(size(t)); % Step force input (1 N bump)
[y, t_out] = lsim(sys, F, t);

% --- Plot Results ---


figure;
plot(t_out, y, 'b-', 'LineWidth', 2);
grid on;
title('Car Suspension: Displacement Response to Bump');
xlabel('Time (seconds)');
ylabel('Displacement y (meters)');
legend('Car Body Displacement');

% --- Also show the step response directly ---


figure;
step(sys);
title('Step Response of Mass-Spring-Damper System');
grid on;

After running this code, MATLAB produces a graph showing how the car body displacement changes
after the bump. A well-designed suspension shows fast settling with minimal oscillation — typically
returning to equilibrium within 1–2 seconds.

Problem 2: Electrical System — RLC Circuit (Radio Tuning)

Page 4 of 16
State-Space Models in MATLAB — Real-Life Engineering Applications

2.1 Real-Life Context and Motivation


A radio receiver must be able to select one specific broadcasting frequency from thousands of signals
simultaneously passing through its antenna. The RLC circuit (Resistor-Inductor-Capacitor) acts as a
bandpass filter that resonates at a specific frequency, amplifying signals near that frequency while
rejecting all others.

The three components serve distinct roles:


• Resistor (R): Provides resistance and controls how sharply the circuit is tuned. Higher R means
broader bandwidth but less selectivity.
• Inductor (L): Stores energy in a magnetic field. Opposes changes in current.
• Capacitor (C): Stores energy in an electric field. Opposes changes in voltage.

Engineering Goal: Tune the RLC circuit to resonate at a desired radio frequency, allowing only
that signal to pass through while all other frequencies are attenuated.

2.2 Step 1 — Deriving the Differential Equation


We apply Kirchhoff's Voltage Law (KVL) around the series RLC loop. Let q be the total charge stored in
the capacitor:

• Voltage across resistor: V_R = R·i = R·(dq/dt)


• Voltage across inductor: V_L = L·(di/dt) = L·(d²q/dt²)
• Voltage across capacitor: V_C = q/C

KVL: L·(d²q/dt²) + R·(dq/dt) + (1/C)·q = V_in(t)

We now switch to the more natural state variables — current and capacitor voltage — rather than
charge, because these are directly measurable in a real circuit.

Using the relationships i_L = dq/dt (inductor current) and V_C = q/C:
L·(di_L/dt) + R·i_L + V_C = V_in
C·(dV_C/dt) = i_L

2.3 Step 2 — Selecting State Variables


x₁ = i_L (current through the inductor, in Amperes)
x₂ = V_C (voltage across the capacitor, in Volts)

These two variables form a natural state for the RLC circuit because they represent the energy stored
in the system. Inductor energy is (1/2)·L·i² and capacitor energy is (1/2)·C·V². Together they capture all
the information needed to predict future behavior.

Page 5 of 16
State-Space Models in MATLAB — Real-Life Engineering Applications

2.4 Step 3 — Writing the State-Space Equations


Solving for the derivatives of each state variable from the circuit equations:

ẋ₁ = di_L/dt = -(R/L)·x₁ - (1/L)·x₂ + (1/L)·V_in


ẋ₂ = dV_C/dt = (1/C)·x₁

Output is the capacitor voltage (the filtered signal):


y = V_C = x₂

A [ -R/L, -1/L ] [ 1/C, 0 ]


B [ 1/L ] [ 0 ]
C [ 0, 1 ]
D [ 0 ]

2.5 Step 4 — MATLAB Implementation


Using parameters representative of an AM radio band: R = 10 Ω, L = 0.01 H, C = 100 µF. The resonant
frequency is approximately f₀ = 1/(2π√LC) ≈ 159 Hz.

Complete MATLAB Code:

% ============================================================
% Problem 2: RLC Circuit — Radio Tuner
% State-Space Model in MATLAB
% ============================================================

% --- Circuit Parameters ---


R = 10; % Resistance (Ohms)
L = 0.01; % Inductance (Henries)
C = 100e-6; % Capacitance (Farads, 100 microfarads)

% --- State-Space Matrices ---


A = [-R/L, -1/L;
1/C, 0 ];

B = [1/L;
0 ];

C_mat = [0, 1]; % Output: capacitor voltage V_C = x2

D = [0];

% --- Create State-Space System Object ---

Page 6 of 16
State-Space Models in MATLAB — Real-Life Engineering Applications

sys = ss(A, B, C_mat, D);

% --- Compute Resonant Frequency ---


f0 = 1/(2*pi*sqrt(L*C));
fprintf('Resonant Frequency: %.2f Hz\n', f0);

% --- Frequency Response (Bode Plot) ---


figure;
bode(sys);
title('RLC Circuit Frequency Response (Radio Tuner)');
grid on;

% --- Step Response ---


figure;
step(sys);
title('RLC Circuit: Step Response');
grid on;

% --- Simulate with a sinusoidal input at resonant frequency ---


t = 0:0.0001:0.1;
V_in = sin(2*pi*f0*t); % Input at resonant frequency
[y, t_out] = lsim(sys, V_in, t);

figure;
plot(t_out, V_in, 'r--', 'LineWidth', 1.5); hold on;
plot(t_out, y, 'b-', 'LineWidth', 2);
legend('Input V_{in}', 'Output V_C (filtered)');
title('RLC Filter Response at Resonant Frequency');
xlabel('Time (s)'); ylabel('Voltage (V)');
grid on;

Problem 3: Thermal System — Room Heating

3.1 Real-Life Context and Motivation


In buildings, maintaining a comfortable indoor temperature despite changing outdoor weather
conditions is an everyday engineering challenge. The heating system must continuously adjust its
output to counteract heat losses through walls, windows, and the roof, while compensating for the cold
outside environment.

This system involves:


• A room with thermal capacitance C_th (Joules/°C): The ability of the room's air, furniture, and
walls to store thermal energy.
• Thermal resistance R_th (°C/Watt): Represents how well the walls and insulation slow heat loss
to the outside.

Page 7 of 16
State-Space Models in MATLAB — Real-Life Engineering Applications

• Heater input q_in (Watts): The power supplied by the heating system.
• Outside temperature T_o (°C): The external disturbance trying to lower the room temperature.

Engineering Goal: Design a control system that keeps the room temperature T_r at a desired
setpoint despite cold outside conditions, using minimum heater energy.

3.2 Step 1 — Deriving the Differential Equation


We apply the principle of energy conservation (thermal balance). The rate of change of thermal energy
stored in the room equals the heat flowing in minus the heat flowing out:

Energy balance: C_th · (dT_r/dt) = q_in - (T_r - T_o)/R_th

The term (T_r - T_o)/R_th represents the rate of heat loss through the walls — proportional to the
temperature difference and inversely proportional to the insulation quality (thermal resistance).

Assuming the outside temperature T_o is approximately constant (or absorbed into the equilibrium
analysis), the equation simplifies to:
C_th · (dT_r/dt) = q_in - T_r/R_th
Dividing by C_th: dT_r/dt = -(1/(R_th·C_th))·T_r +
(1/C_th)·q_in

3.3 Step 2 — Selecting State Variables


This is a 1st-order system, so we need only ONE state variable:

x = T_r (room temperature in degrees Celsius)

The room temperature completely captures the system's thermal state. Knowing T_r at any moment
and knowing the future heater input q_in is sufficient to predict all future temperatures.

3.4 Step 3 — Writing the State-Space Equations


ẋ = -(1/(R_th·C_th))·x + (1/C_th)·q_in

Output is simply the room temperature itself (what a thermostat measures):


y = T_r = x

A [ -1/(R_th · C_th) ] (scalar, 1×1 matrix)


B [ 1/C_th ] (scalar)
C [ 1 ] (scalar)
D [ 0 ] (scalar)

Page 8 of 16
State-Space Models in MATLAB — Real-Life Engineering Applications

3.5 Step 4 — MATLAB Implementation


Using typical room parameters: C_th = 5000 J/°C (thermal mass of a medium room), R_th = 0.05 °C/W
(moderate insulation). Initial room temperature 10°C, heater output 2000 W.

Complete MATLAB Code:

% ============================================================
% Problem 3: Room Heating — Thermal State-Space Model
% ============================================================

% --- Thermal Parameters ---


C_th = 5000; % Thermal capacitance (J/deg C)
R_th = 0.05; % Thermal resistance (deg C/W)
T_o = 5; % Outside temperature (deg C) - constant

% --- State-Space Matrices ---


A = -1/(R_th * C_th); % Scalar system matrix
B = 1/C_th; % Scalar input matrix
C_mat = 1; % Output: room temperature directly
D = 0;

% --- Create State-Space System Object ---


sys = ss(A, B, C_mat, D);

% --- Simulation Setup ---


t = 0:60:7200; % 0 to 2 hours, step every 60 seconds
q_in = 2000*ones(size(t)); % Constant heater: 2000 Watts

% Initial condition: room starts at 10 deg C


x0 = 10;
[y, t_out, x] = lsim(sys, q_in, t, x0);

% --- Plot Temperature Response ---


figure;
plot(t_out/60, y, 'r-', 'LineWidth', 2.5);
hold on;
yline(T_o, 'b--', 'LineWidth', 1.5, 'Label', 'Outside Temp');
grid on;
title('Room Heating: Temperature Response Over Time');
xlabel('Time (minutes)');
ylabel('Room Temperature (deg C)');
legend('Room Temperature', 'Outside Temperature');

% --- Steady-State Temperature ---


T_ss = -B/A * 2000 + 0; % Steady-state = -(B/A)*u

Page 9 of 16
State-Space Models in MATLAB — Real-Life Engineering Applications

fprintf('Steady-state room temperature: %.1f deg C\n', T_ss);

Problem 4: Fluid System — Water Tank Level Control

4.1 Real-Life Context and Motivation


Water level control appears in countless industrial applications: municipal water towers, chemical
processing tanks, irrigation reservoirs, hydraulic systems, and food processing plants. The fundamental
challenge is maintaining a desired liquid height in the face of varying inlet flow rates and outlet
demands.

The physical system consists of:


• A tank with cross-sectional area A (m²): The container holding the fluid.
• An inlet flow q_in (m³/s): The controlled input — water pumped into the tank.
• A gravity-driven outlet flow: Water exits through an orifice at the bottom. The flow rate depends
on the height h, giving q_out = (ρgh)/R where ρ is fluid density, g is gravity, and R is the outlet
resistance.

Engineering Goal: Control the inlet flow q_in to maintain the water height h at a desired level,
even as demand (outlet flow) varies.

4.2 Step 1 — Deriving the Differential Equation


We apply the conservation of mass (continuity equation). The rate of change of volume stored in the
tank equals the flow rate in minus the flow rate out:

A · (dh/dt) = q_in - q_out

For gravity-driven outflow, we use the linearized Torricelli flow model:


q_out = (ρ·g·h) / R (linearized around operating point)

Substituting and rearranging:


A · (dh/dt) = q_in - (ρ·g/R)·h
Dividing by A: dh/dt = -(ρg)/(AR) · h + (1/A) · q_in

4.3 Step 2 — Selecting State Variables


This is a 1st-order system, requiring only one state variable:

x = h (water height in meters)

Page 10 of 16
State-Space Models in MATLAB — Real-Life Engineering Applications

The water height h captures all the energy state of the fluid system (potential energy ∝ h). Knowing h
and the future inlet flow fully determines the system's future evolution.

4.4 Step 3 — Writing the State-Space Equations


ẋ = -(ρ·g)/(A·R) · x + (1/A) · q_in

Output is the water height (what a level sensor measures):


y = h = x

A [ -(rho·g)/(A·R) ] (1×1, scalar)


B [ 1/A ] (scalar)
C [ 1 ] (scalar — measure height directly)
D [ 0 ] (scalar)

4.5 Step 4 — MATLAB Implementation


Using: tank area A = 2 m², outlet resistance R = 1000 Pa·s/m³, water density ρ = 1000 kg/m³, gravity g
= 9.81 m/s². Initial height 0 m, step inlet flow of 0.01 m³/s.

Complete MATLAB Code:

% ============================================================
% Problem 4: Water Tank Level Control — Fluid System
% ============================================================

% --- Physical Parameters ---


rho = 1000; % Water density (kg/m^3)
g = 9.81; % Gravitational acceleration (m/s^2)
A = 2.0; % Tank cross-sectional area (m^2)
R = 1000; % Outlet resistance (Pa.s/m^3)

% --- State-Space Matrices ---


A_mat = -(rho*g)/(A*R); % System matrix (scalar)
B_mat = 1/A; % Input matrix (scalar)
C_mat = 1; % Output matrix
D_mat = 0;

% --- Create State-Space System ---


sys = ss(A_mat, B_mat, C_mat, D_mat);

% --- Steady-state height for 0.01 m^3/s inlet ---


q_in_ss = 0.01;
h_ss = -(B_mat/A_mat)*q_in_ss;

Page 11 of 16
State-Space Models in MATLAB — Real-Life Engineering Applications

fprintf('Steady-state water height: %.3f m\n', h_ss);

% --- Simulation ---


t = 0:10:3600; % 0 to 1 hour, 10-second steps
q_in = 0.01*ones(size(t)); % Constant inlet flow 0.01 m^3/s
x0 = 0; % Tank starts empty
[y, t_out] = lsim(sys, q_in, t, x0);

% --- Plot Results ---


figure;
plot(t_out/60, y, 'c-', 'LineWidth', 2.5);
hold on;
yline(h_ss, 'r--', 'LineWidth', 1.5, 'Label', 'Steady-State Height');
grid on;
title('Water Tank: Level Response to Constant Inlet Flow');
xlabel('Time (minutes)');
ylabel('Water Height h (meters)');
legend('Water Level', 'Steady-State Level');

% --- Step Response (normalized) ---


figure;
step(sys);
title('Water Tank Step Response');
grid on;

Problem 5: Aerospace — Satellite Pitch (Attitude) Control

5.1 Real-Life Context and Motivation


Satellites in orbit must maintain precise orientation (attitude) at all times. Communication satellites need
to point their antennas toward Earth. Earth observation satellites must point their cameras at target
locations. Scientific satellites must orient their instruments toward celestial objects.

Unlike atmospheric aircraft, a satellite operates in the vacuum of space. There is no air resistance, so:
• There is no aerodynamic damping — once set in rotation, a satellite would spin forever without
active correction.
• The only forces available for attitude control are reaction wheels (internal momentum
exchange), magnetorquers (magnetic field interaction), and thrusters (firing small jets of
propellant).

This problem models the pitch (nose-up/nose-down rotation) axis of a satellite controlled by a thruster
producing a torque M(t).

Engineering Goal: Apply precise, timed thruster firings (torque pulses) to rotate the satellite to a
desired pitch angle and hold it there with zero angular velocity.

Page 12 of 16
State-Space Models in MATLAB — Real-Life Engineering Applications

5.2 Step 1 — Deriving the Differential Equation


We apply Newton's Second Law for rotational motion (Euler's Rotation Equation about the pitch axis):

Net torque = Moment of inertia × Angular acceleration


J · (d²θ/dt²) = M(t)

Where:
• J = Moment of inertia about the pitch axis (kg·m²)
• θ = Pitch angle (radians)
• M(t) = Applied torque from thrusters (N·m)

In the space environment, there is essentially no damping (no atmosphere), so no damping term
appears. This makes the system a pure double integrator — a fundamental and challenging control
problem because it has two poles at the origin of the complex plane (on the stability boundary).

5.3 Step 2 — Selecting State Variables


The 2nd-order differential equation requires two state variables:

x₁ = θ (pitch angle — orientation in radians)


x₂ = θ̇ = dθ/dt (angular velocity — rate of rotation in rad/s)

Physically, both variables are measured by sensors on the satellite: x₁ by a star tracker or gyroscope
(integrated), and x₂ directly by a rate gyroscope. Both are needed for attitude control algorithms.

5.4 Step 3 — Writing the State-Space Equations


Writing the first derivatives of each state variable:

ẋ₁ = x₂ (angle changes at rate = angular


velocity)
ẋ₂ = (1/J) · M(t) (angular velocity changes due to
torque/inertia)

Output is the pitch angle (what we command and measure):


y = θ = x₁

A [ 0, 1 ] [ 0, 0 ] (double integrator — no natural


dynamics)
B [ 0 ] [ 1/J ]
C [ 1, 0 ] (measure pitch angle)

Page 13 of 16
State-Space Models in MATLAB — Real-Life Engineering Applications

D [ 0 ]

Note that the A matrix has two eigenvalues at zero (both at the origin). This means the open-loop
system is marginally stable — it does not settle to any equilibrium on its own. Active feedback control is
essential.

5.5 Step 4 — MATLAB Implementation


Using: moment of inertia J = 1000 kg·m² (typical small satellite). We apply a torque pulse, then analyze
the response and design a proportional-derivative (PD) controller to stabilize the system.

Complete MATLAB Code:

% ============================================================
% Problem 5: Satellite Pitch Control — Aerospace System
% ============================================================

% --- Satellite Parameters ---


J = 1000; % Moment of inertia (kg.m^2)

% --- State-Space Matrices (Open Loop) ---


A = [0, 1;
0, 0];

B = [0;
1/J];

C = [1, 0]; % Output: pitch angle theta = x1

D = [0];

% --- Open-Loop System Object ---


sys_ol = ss(A, B, C, D);

% --- Check open-loop eigenvalues ---


disp('Open-loop eigenvalues:');
disp(eig(A)); % Both zero: marginally stable

% --- PD Controller Design for Stability ---


% u = -Kp*x1 - Kd*x2 (state feedback)
Kp = 0.5; % Proportional gain
Kd = 50; % Derivative gain
K = [Kp, Kd]; % State feedback gain vector

% Closed-loop: A_cl = A - B*K


A_cl = A - B*K;

Page 14 of 16
State-Space Models in MATLAB — Real-Life Engineering Applications

sys_cl = ss(A_cl, B, C, D);

disp('Closed-loop eigenvalues:');
disp(eig(A_cl)); % Now in left-half plane (stable!)

% --- Simulate: Torque pulse for 1 second ---


t = 0:0.1:120; % 0 to 2 minutes
M = zeros(size(t));
M(t <= 1) = 10; % 10 N.m torque for first second

% Closed-loop response from initial conditions


x0 = [0; 0];
[y_cl, t_out] = lsim(sys_cl, M, t, x0);

% --- Plot: Open vs Closed Loop ---


figure;
subplot(2,1,1);
lsim(sys_ol, M, t);
title('Open-Loop: Satellite Pitch (No Control — Drifts!)');
ylabel('Pitch Angle (rad)');

subplot(2,1,2);
plot(t_out, y_cl, 'm-', 'LineWidth', 2);
title('Closed-Loop: Satellite Pitch with PD Control');
xlabel('Time (s)'); ylabel('Pitch Angle (rad)');
grid on;

% --- Step response of closed-loop ---


figure;
step(sys_cl);
title('Closed-Loop Step Response: Pitch Control');
grid on;

Summary: Comparison of All Five Systems

The table below summarizes the key characteristics of each state-space model developed in this
document:

System Order State x Input u Output y


Mass-Spring-Damper 2nd y, dy/dt Force F(t) y (displacement)
RLC Circuit 2nd iL, vC Voltage Vin vC (voltage)
Room Heating 1st Tr (temp) Heater qin Tr (temperature)
Water Tank 1st h (height) Flow qin h (height)

Page 15 of 16
State-Space Models in MATLAB — Real-Life Engineering Applications

Satellite Pitch 2nd theta, dtheta/dt Torque M theta (angle)

Key Observations and Lessons


• System Order and State Variables: The order of the differential equation determines the number
of state variables needed. 1st-order systems (thermal, fluid) need 1 state variable. 2nd-order
systems (mechanical, electrical, aerospace) need 2 state variables.
• The A Matrix Governs Natural Behavior: All eigenvalues of A in the left-half plane means the
system is naturally stable (thermal, fluid, suspension). Eigenvalues on the imaginary axis (RLC
at resonance, satellite) indicate marginal stability requiring control.
• Physical Meaning of States: State variables always represent real, measurable physical
quantities — displacement, velocity, temperature, water level, current, voltage, angle. This
makes state-space models physically meaningful and practically useful.
• MATLAB Workflow is Universal: The same ss(), step(), lsim(), bode(), and eig() commands work
for ALL five systems. The only difference is the numerical values in the A, B, C, D matrices.
• Control Design Extension: Once the state-space model is built, MATLAB's Control System
Toolbox provides place() for pole placement, lqr() for optimal control, and kalman() for state
estimation — all building directly on the ss() object.

MATLAB Command Quick Reference

sys = ss(A, B, C, D) % Create state-space system object


step(sys) % Plot unit step response
impulse(sys) % Plot impulse response
lsim(sys, u, t) % Simulate with arbitrary input u
lsim(sys, u, t, x0) % Simulate with initial conditions x0
bode(sys) % Frequency response (Bode plot)
eig(A) % Find eigenvalues of A matrix
pole(sys) % Find system poles
zero(sys) % Find system zeros
tf(sys) % Convert to transfer function form
pzmap(sys) % Pole-zero map
K = place(A, B, desired_poles) % Pole placement control design
K = lqr(A, B, Q, R) % Optimal LQR control design
feedback(sys, K) % Create closed-loop system

End of Document — State-Space Models in MATLAB: Five Real-Life Engineering Problems

Page 16 of 16

You might also like