When simulating the response to a specific input signal, the input data U must be a matrix with as many rows as samples in the time vector T, and as many columns as input channels.

1 次查看(过去 30 天)
Hi all, I'm getting an error with the u matrix, the situation is 3 train carts coming to a rest so, there is a pulling force represented by the u matrix. I left in the sinusoidal force as that gave results but, I would like to get results with initial parameters.
Thanks, Zain
clear
clc
m1 = 69000;
m2 = 65000;
m3 = 126000;
k1 = 8000;
k2 = 8500;
c1 = 5200;
c2 = 6000;
%to = 0:0.5:10
Z = zeros(3);
M = [m1 0 0; 0 m2 0; 0 0 m3];
Co = [c1 -c1 0;-c1 (c2+c1) -c2; 0 -c2 c2];
K = [k1 -k1 0; -k1 (k1+k2) -k2; 0 -k2 k2];
Minv = inv(M);
I = eye(3);
MC = Minv*Co;
KC = Minv*K;
A = [-MC -KC; I Z];
B = eye(6);
C = eye(6);
D = zeros(6);
state = ss(A,B,C,D)
t = 0:0.01:20;
%u = 158005*sin(3.142*t);
u = [87567; 0; 0; 0; 0; 0];
u = repmat(u, 6, 1);
sys = ss(A,B,C,D);
x0 = [4.17;4.17;4.17;0;0;0];
y = lsim(state,u,t,x0);
hold on
x1 = y(:,1);
figure(1)
xlabel('Time (s)');
ylabel('Displacement');
title('Displacement against time')
plot(t,x1)
grid
hold off

采纳的回答

Mathieu NOE
Mathieu NOE 2020-11-29
hello
this seems to work better :
clear
clc
m1 = 69000;
m2 = 65000;
m3 = 126000;
k1 = 8000;
k2 = 8500;
c1 = 5200;
c2 = 6000;
%to = 0:0.5:10
Z = zeros(3);
M = [m1 0 0; 0 m2 0; 0 0 m3];
Co = [c1 -c1 0;-c1 (c2+c1) -c2; 0 -c2 c2];
K = [k1 -k1 0; -k1 (k1+k2) -k2; 0 -k2 k2];
Minv = inv(M);
I = eye(3);
MC = Minv*Co;
KC = Minv*K;
A = [-MC -KC; I Z];
B = eye(6);
C = eye(6);
D = zeros(6);
state = ss(A,B,C,D)
t = 0:0.01:20;
%u = 158005*sin(3.142*t);
u = [87567; 0; 0; 0; 0; 0];
% u = repmat(u, 6, 1);
u = u*ones(1,length(t));
sys = ss(A,B,C,D);
x0 = [4.17;4.17;4.17;0;0;0];
y = lsim(state,u,t,x0);
hold on
x1 = y(:,1);
figure(1)
xlabel('Time (s)');
ylabel('Displacement');
title('Displacement against time')
plot(t,x1)
grid
hold off

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by