Question: clc clear all syms x x 1 x 2 x 3 x 4 u A = [ - 8 6 1 0 0 8 0

clc
clear all
syms x x1 x2 x3 x4 u
A =[-861008083.4; 86100-8488; 1000; 0100];
B =[1315.6;-1315.6;0;0];
W=ctrb(A,B);
E=rank(W)
[n, m]= size(B);
[Q, R]= qr(B);
T =[Q((m+1):n,:); Q(1:m,:)];
Acap = T * A * inv(T);
Bcap = T * B;
A11= Acap(1:n-m,1:n-m);
A12= Acap(1:n-m,n-m+1:n);
A21= Acap(n-m+1:n,1:n-m);
A22= Acap(n-m+1:n,n-m+1:n);
B2= Bcap(n-m+1:n,1:m);
P =[-3-4-5];
g = place(A11, A12, P);
Gcap =[g 1];
G =-Gcap * T;
ueq =-(inv(G * B)* G * A)*[x1; x2; x3; x4];
s =0.1643*x1-1.2499*x2+0.2097*x3-16.7608*x4;
usw = zeros(size(s));
tspan =0:0.01:10;
x0=[-5; 5; 10; -3];
[t, x]= ode45(@(t, x) systemODE(t, x, G, B, A, usw), tspan, x0);
u = zeros(size(t));
v(1)=0.01; % Initial value for z
for i =1:length(t)
ueq =-(inv(G * B)* G * A)* x(i,1:4)';
s =0.1643*x(i,1)-1.2499*x(i,2)+0.2097*x(i,3)+16.7608*x(i,4);
% Numerical integration of z_dot
v_dot =-0.01*sign(s);
v(i+1)= v(i)+0.01* v_dot; % Using Euler's method
% Calculate u_sw
usw(i)=-0.01* s^0.5*sign(s)+ v(i+1);
% Total control input
u(i)= ueq + usw(i);
end
% Plot u vs t
figure;
subplot(2,1,1);
plot(t, u);
xlabel('Time (s)');
ylabel('u');
title('Control Input u vs Time');
% Plot states vs t
subplot(2,1,2);
plot(t, x);
legend('x1','x2','x3','x4');
xlabel('Time (s)');
ylabel('States');
title('States x1, x2, x3, x4 vs Time');
% Define the system of differential equations
function dxdt = systemODE(t, x, G, B, A, usw)
ueq =-(inv(G*B)*G*A)*x;
s =0.1643*x(1)-1.2499*x(2)+0.2097*x(3)-16.7608*x(4);
u = ueq + usw;
% State equations
dxdt =[-861*x(1)+8083.4*x(4)+1315.6*u; 861*x(1)-8488*x(4)-1315.6*u ; x(1); x(2)];
end.
THis is the matlab code for super twisted sliding mode control to stablize the system. but one of the system state x3 is unstable. please debug the code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!