- A is an Nx-by-Nx real- or complex-valued matrix.
- B is an Nx-by-Nu real- or complex-valued matrix.
- C is an Ny-by-Nx real- or complex-valued matrix.
- D is an Ny-by-Nu real- or complex-valued matrix.
Matrices do not have the same number of columns
7 views (last 30 days)
Show older comments
I am simulating a half-car model using a Mass & Stiffness Matrices and have run into an error nested with the "ss" function which states: "Error using ss (line 355); The "A" and "C" matrices must have the same number of columns."
In the workspace, I can observe that the A matrix is a 10x10 matrix, where b,c,d are 5x5. The first 5x5 within the A matrix is simply the identity matrix but this should not be included. I am using "A = [ zeros(5,5) eye(5); -inv(M)*K -inv(M)*C ]" in place of A = [ 0 i ; -inv(M)*k -inv(M)*C]
The code is as follows:
% Parameters
m1 = 125; %kg %unsprung mass
m2 = 100; %kg %unsprung mass
m3 = 1425; %kg %sprung mass
m4 = 75; %kg %driver mass
I = 8500; %kg-m^2 %moment of Inertia
kt = 350000; %N/m %tire stiffness
k1 = 100000; %N/m %front suspension stiffness
k2 = 100000; %N/m %rear suspension stiffness
k3 = 30000; %N/m %seat stiffness
C = 0.002; %N-s/m %damping constant
% Mass Matrix
M = [m1 0 0 0 0
0 m2 0 0 0
0 0 m3 0 0
0 0 0 m4 0
0 0 0 0 I];
% Stiffness Matrix
K = [(kt +k1) 0 -k1 0 k1
0 (kt+k2) -k2 0 k2
-k1 -k2 (k3+k2+k1) -k3 (-k3+k2-k1)
0 0 -k3 k3 k3
-k1 -k2 (k3+k2+k1) -k3 (-k3+k2-k1)];
% Identity Matrix
i = [1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1];
% A Matrix
A = [ zeros(5,5) eye(5); -inv(M)*K -inv(M)*C ];
% b Matrix
b = [0 0 0 0 0 500/m1 0 0 0 0]';
%c state variable
c = [C * i];
% d state variable
d=[0];
% Part 1
sys1=ss(A,b,c,d);
% Bode plot
bode(sys1,{1,100});
% pole-zero plot
pzmap(sys1);axis([-80 80 -80 80]);
% impulse
impulse(sys1,30);
%RMS output for 30 sec
rms(impulse(sys1,30));
%undamped natural frequencies
sort(sqrt(abs(eig(-inv(M)*K)))) ;
End of code
any help is much appreciated!
0 Comments
Answers (1)
Walter Roberson
on 25 Mar 2025
A = [ zeros(5,5) eye(5); -inv(M)*K -inv(M)*C ];
That has 10 columns -- 5 of zeros and 5 of eye
C = 0.002; %N-s/m %damping constant
A constant.
i = [1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1];
That has 5 columns. It could have been written as i = eye(5);
c = [C * i];
Constant times matrix with 5 columns gives you 5 columns of output.
sys1=ss(A,b,c,d);
A has 10 columns, c has 5 columns; the combination is not permitted.
The state-space matrices are:
If A is 10 x 10, then B must be 10 x something; we see by examination that indeed B is 10 x 1.
If B is 10 x 1 then Nu must be 1.
If C is something by Nx then C must be something by 10. Suppose it were 5 x 10.
Then D must be the same number of rows as C is, and must have Nu columns, where we have already found the Nu is 1. So D would have to be 5 x 1.
Or, working backwards,
If D is 1 x 1 then Ny = 1 and Nu = 1.
Then C would have to be 1 x Nx, value of Nx to be determined.
Then B would have to be Nx x 1, value of Nx to be determined.
With A being 10 x 10, that gives us our Nx, and it follows that:
A is 10 x 10
B is 10 x 1
C is 1 x 10
D is 1 x 1
Or if we assume the C is the correct size, 5 x 5 then
A would have to be 5 x 5
B would have to be 5 x Nu
C would be 5 x 5 by assumption
D would be 5 x Nu
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!