I have an error when simulate a linear delay system with sliding mode control
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']);
Accepted Answer
More Answers (0)
Categories
Find more on Linearization 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!