You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

离散系统状态空间转传递函数Matlab报错:A与C矩阵列数不匹配

Fixing ss2tf Error & Correct State-Space to Transfer Function Conversion in MATLAB

Let's break down your issue step by step:

First: The Root Cause of the Error

The error The A and C matrices must have the same number of columns happens because your C matrix has the wrong dimensions. Your A matrix is 2×2 (representing a 2-state system), but you defined C = [1,0,0] which is 1×3. MATLAB requires C to have exactly as many columns as A (one column per state variable). That's the immediate fix you need.

Next: Correcting the State-Space Model

Your original discrete system is:

y(k+2) + 4y(k+1) + 5y(k) = u(k+2) + 2u(k+1) + u(k)

First, let's confirm the transfer function via z-transform:

  • Take z-transform of both sides:
    z²Y(z) + 4zY(z) + 5Y(z) = z²U(z) + 2zU(z) + U(z)
  • Rearrange to get the transfer function:
    G(z) = Y(z)/U(z) = (z² + 2z + 1)/(z² + 4z + 5)

This is a proper rational function (matching numerator/denominator order), so D=1 (your manual calculation here was correct). Now, let's fix the state-space matrices:

Option 1: Match your manual B matrix with a corrected C matrix

Your A and B matrices are valid for one state-space representation of the system. You just need to fix C to be 1×2 (matching A's column count). Use C = [1, 0] (since this corresponds to outputting the first state variable, which is y(k)):

% Corrected state-space matrices
A = [0, 1; -5, -4];
B = [-2; 4];
C = [1, 0]; % Fixed to 1x2
D = 1;

% Convert to transfer function
[N1, D1] = ss2tf(A, B, C, D, 1);
H = tf(N1, D1, 1); % 1 = sampling time

% Output the result
disp("Discrete Transfer Function:");
disp(H);

Option 2: Use the standard controllable canonical form

If you want to use the standard state-space structure for this system, here's the valid matrix set (derived from the transfer function's strict rational part G(z) = 1 + (-2z -4)/(z² +4z +5)):

A = [0, 1; -5, -4];
B = [0; 1];
C = [-2, -4];
D = 1;

[N1, D1] = ss2tf(A, B, C, D, 1);
H = tf(N1, D1, 1);

disp("Discrete Transfer Function:");
disp(H);

Both Options Will Output the Correct Transfer Function

Either code will give you the expected result:

Transfer function:
z^2 + 2 z + 1
-------------
z^2 + 4 z + 5

Sampling time: 1
Discrete-time transfer function.

Key Takeaway

State-space representations are not unique—multiple A/B/C/D sets can describe the same system. The critical rule you broke was mismatching C's column count to A's, which caused the ss2tf error.

内容的提问来源于stack exchange,提问作者MohammedALNasrawi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:10:58