I have an error when simulate a linear delay system with sliding mode control
5 views (last 30 days)
Show older comments
% Define the system matrices
A = [-1];
B = [1];
C = [1];
D = 0;
% Define the delay
tau = 0.5; % assume a 0.5 s delay
% Define the sliding mode control parameters
alpha = 1;
beta = 1;
theta = 1;
t = 0:0.01:2;
% Create the delayed state-space model
nx = size(A,1);
ny = size(C,1);
nd = round(tau/(t(2)-t(1)));
Ad = [A zeros(nx,nd); zeros(nd,nx) eye(nd)];
Bd = [B; zeros(nd,1)];
Cd = [C zeros(ny,nd)];
Dd = D;
sys_delayed = ss(Ad,Bd,Cd,Dd,t(1));
% Set up the sliding mode controller
Am = [A, zeros(nx,1); -C, 0];
Bm = [B; 0];
K = [alpha, beta];
L = [1, 0];
Gamma = [-theta*beta*C*B, theta*alpha*C*A-beta*C*B];
% Simulate the response to a step input with sliding mode control
% t = 0:0.01:2;
u = ones(size(t));
x0 = [0; 0];
s0 = L*x0;
[~,S,X] = lsim(sys_delayed, [u'; s0'], t, [x0; s0']);
for i=1:length(t)
s = S(i,:)';
x = X(i,:)';
xdot = Am*x + Bm*u(i);
udot = -K*s - Gamma*x;
u(i) = u(i) + udot*0.01;
end
% Plot the response
plot(t,X(:,1),t,u)
xlabel('Time (s)')
ylabel('Temperature')
legend('Temperature', 'Control input')
%%%-------------------------------------------
Error using DynamicSystem/lsim (line 84)
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.
Error in Exemple_delay_sys_ordre1_SMC1 (line 38)
[~,S,X] = lsim(sys_delayed, [u'; s0'], t, [x0; s0']);
0 Comments
Accepted Answer
Paul
on 18 Feb 2023
Hi yousra,
I'm not quite sure what the code is trying to do. However, the reason for the lsim error is pretty clear, and there's another issue in that lsim call that needs to be addressed as well.
% Define the system matrices
A = [-1];
B = [1];
C = [1];
D = 0;
% Define the delay
tau = 0.5; % assume a 0.5 s delay
% Define the sliding mode control parameters
alpha = 1;
beta = 1;
theta = 1;
% define the time vector
t = 0:0.01:2;
% Create the delayed state-space model
nx = size(A,1);
ny = size(C,1);
nd = round(tau/(t(2)-t(1)));
Ad = [A zeros(nx,nd); zeros(nd,nx) eye(nd)];
Bd = [B; zeros(nd,1)];
Cd = [C zeros(ny,nd)];
Dd = D;
sys_delayed = ss(Ad,Bd,Cd,Dd,t(1));
% Set up the sliding mode controller
Am = [A, zeros(nx,1); -C, 0];
Bm = [B; 0];
K = [alpha, beta];
L = [1, 0];
Gamma = [-theta*beta*C*B, theta*alpha*C*A-beta*C*B];
% Simulate the response to a step input with sliding mode control
% t = 0:0.01:2;
u = ones(size(t));
x0 = [0; 0];
s0 = L*x0;
At this point u and t have the same number of elements. So appending the additional elements to u in the second input to lsim causes the error.
Also, sys_delayed has 51 states
size(sys_delayed)
But the initial conditions input to lsim only has three elements, so that's another problem that needs to be addressed.
size([x0; s0'])
[~,S,X] = lsim(sys_delayed, [u'; s0'], t, [x0; s0']);
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!