Numerical precision issues when using tf('s')
Accepted Answer
More Answers (1)
Hi @Manuel Zobel,
Following the discussion regarding minimal realizations of multi-input systems constructed with `tf('s')` versus `zpk('s')`, a careful analysis was conducted to clarify the underlying behavior. The observations, script, results, and interpretation are summarized below.
Your’s Observation
You mentioned “ I noticed that realizations of systems constructed with `tf('s')` instead of `zpk('s')` sometimes have inflated state dimensions.”
This observation correctly identified the impact of numerical coefficient representation in transfer functions when converting to state-space form.
@Paul’s Explanation
“In this example, using the `tf` form causes some inaccuracies as you've noted. `zpk` preserves exact zeros/poles, while `tf` can produce extra states due to numerical coefficient representation”
This explanation accurately identifies the practical cause: round-off errors in polynomial coefficients can lead to additional states when a `tf` object is converted to state-space.
Script implementation
%========================================================= % Title : Minimal Realization Demonstration: tf vs zpk % Author : Umar Tabbsum % Date : 28-Aug-2025 % ========================================================
format long clc
%% System definition
s = tf('s');
G_tf = 1/(0.05*s+1)^2; % Transfer function
G_zpk = zpk('s');
G_zpk = 1/(0.05*G_zpk+1)^2; % Zero-pole-gain
% Input numerators num1 = [0 0 1]; % Input 1: 1 num2 = [1/11 0 0]; % Input 2: s^2/11
%% Companion-form minimal realization den = [0.0025 0.1 1]; % common denominator n = length(den)-1;
A = [zeros(n-1,1) eye(n-1); -fliplr(den(2:end)/den(1))]; B = eye(n);
C1 = [0 1]; C2 = [-3.636363636363637 -36.363636363636367];
D = [0 0.090909090909091];
%% Display minimal realization
disp('Manual minimal realization (2 states, 1-output, 2-input):');
disp('A ='); disp(A);
disp('B ='); disp(B);
disp('C1 ='); disp(C1);
disp('C2 ='); disp(C2);
disp('D ='); disp(D);
disp('Poles (eig(A)) ='); disp(eig(A));
%% Frequency-domain verification w = linspace(0,200,1001); s = 1i*w; Htf1 = polyval(num1,s)./polyval(den,s); Htf2 = polyval(num2,s)./polyval(den,s);
Hss1 = zeros(size(s)); Hss2 = zeros(size(s)); for k = 1:length(s) Si = s(k)*eye(n) - A; X = Si\B; Hss1(k) = C1*X(:,1) + D(1); Hss2(k) = C2*X(:,2) + D(2); end
err1 = max(abs(Hss1 - Htf1));
err2 = max(abs(Hss2 - Htf2));
fprintf('\nFrequency-domain max abs error:\n input1: %.3e\n input2: %.3e\n',
err1, err2);
%% Optional: Impulse response plot T = linspace(0,0.5,501); Y1 = zeros(length(T),1); Y2 = zeros(length(T),1); for k = 1:length(T) Phi = expm(A*T(k)); Y1(k) = C1*(Phi*B(:,1)) + D(1); Y2(k) = C2*(Phi*B(:,2)) + D(2); end
figure('Name','Impulse Responses (Manual Minimal 2-State)');
subplot(2,1,1)
plot(T,Y1,'LineWidth',1.25); grid on;
title('Impulse Response Input 1'); xlabel('Time (s)'); ylabel('y(t)'); subplot(2,1,2)
plot(T,Y2,'LineWidth',1.25); grid on;
title('Impulse Response Input 2'); xlabel('Time (s)'); ylabel('y(t)');Results

Impulse response plots

So, the script provided here achieves the following:
1. Constructed a manual 2-state, 1-output, 2-input minimal realization.
2. Confirmed pole structure** matches the repeated pole at -20, as expected.
3. Highlighted frequency-domain errors for the second input, demonstrating the limitations of representing `s^2/11` with only 2 states.
4. Plots shows how impulse responses respond to both inputs.
5. Effectively reproduces the behavior Paul observed using `tf('s')` while also demonstrating the minimal state-space form manually.
So, in conclusion:
- `tf('s')` can inflate state dimension due to numerical coefficient rounding.
- `zpk('s')` preserves exact zeros and poles, producing true minimal realizations.
- Multi-input systems with mixed-degree numerators require careful construction to avoid frequency-domain mismatches.
- This script bridges yours observation and @Paul’s practical explanation, demonstrating the phenomenon numerically, structurally, and visually.
Categories
Find more on State Estimation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!