Please can anyone help me to correct this code !!!!
% Définition des matrices de système
A = [0 0 1 -1 0 0; 0 1 0 0 1 0; 0 0 0 0 0 1];
B1 = [0 1 0; 0 0 0; 0 0 0];
B2 = [0 0 1; 0 0 0; 0 0 0];
C1 = [1 0 0; 0 1 0; 0 0 1];
C2 = [0 0 1; 0 0 0; 0 0 0];
D1 = [1 0 0; 0 1 0; 0 0 1];
% Définition des fonctions d’appartenance floues
f1 = @(t) (t – 0.5)^2;
f2 = @(t) t;
% Définition des règles floues
rule1 = ‘IF f1(t) is "Long" and f2(t) is "Extended", THEN _x(t) = A1*x(t) + B1*x(t) + B2*sat(u(t) – s(t))’;
rule2 = ‘IF f1(t) is "Short" and f2(t) is "Compressed", THEN _x(t) = A2*x(t) + B1*x(t) + B2*sat(u(t) – s(t))’;
rule3 = ‘IF f1(t) is "Long" and f2(t) is "Compressed", THEN _x(t) = A3*x(t) + B1*x(t) + B2*sat(u(t) – s(t))’;
rule4 = ‘IF f1(t) is "Short" and f2(t) is "Extended", THEN _x(t) = A4*x(t) + B1*x(t) + B2*sat(u(t) – s(t))’;
% Définition des gains de contrôle
P1 = [1 0 0; 0 1 0; 0 0 1];
P2 = [0 1 0; 0 0 1; 0 0 0];
P3 = [0 0 1; 0 0 0; 0 0 1];
P4 = [1 0 0; 0 1 0; 0 0 1];
% Définition de la fonction de contrôle
control = @(t, x) P1*x + P2*x + P3*sat(u(t) – s(t));
% Simulation
t = 0:0.01:10;
x0 = [1; 0; 0];
u = zeros(size(t));
s = 0.5*t;
z1 = zeros(size(t));
z2 = zeros(size(t));
for i = 1:length(t)
x = x0;
for j = 1:length(t)
if f1(t(j)) > 0.5 && f2(t(j)) > 0.5
x = A1*x + B1*x + B2*sat(u(j) – s(j));
elseif f1(t(j)) < 0.5 && f2(t(j)) < 0.5
x = A2*x + B1*x + B2*sat(u(j) – s(j));
elseif f1(t(j)) > 0.5 && f2(t(j)) < 0.5
x = A3*x + B1*x + B2*sat(u(j) – s(j));
else
x = A4*x + B1*x + B2*sat(u(j) – s(j));
end
end
z1(i) = C1*x;
z2(i) = C2*x;
u(i) = control(t(i), x);
end
% Affichage des résultats
plot(t, z1, t, z2);
xlabel(‘Time (s)’);
ylabel(‘State’);
title(‘Active Suspension System’);
And this the error message ‘ paper1
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of
rows in the second matrix. To perform elementwise multiplication, use ‘.*’.
Error in paper1 (line 42)
x = A2*x + B1*x + B2*sat(u(j) – s(j)); ‘% Définition des matrices de système
A = [0 0 1 -1 0 0; 0 1 0 0 1 0; 0 0 0 0 0 1];
B1 = [0 1 0; 0 0 0; 0 0 0];
B2 = [0 0 1; 0 0 0; 0 0 0];
C1 = [1 0 0; 0 1 0; 0 0 1];
C2 = [0 0 1; 0 0 0; 0 0 0];
D1 = [1 0 0; 0 1 0; 0 0 1];
% Définition des fonctions d’appartenance floues
f1 = @(t) (t – 0.5)^2;
f2 = @(t) t;
% Définition des règles floues
rule1 = ‘IF f1(t) is "Long" and f2(t) is "Extended", THEN _x(t) = A1*x(t) + B1*x(t) + B2*sat(u(t) – s(t))’;
rule2 = ‘IF f1(t) is "Short" and f2(t) is "Compressed", THEN _x(t) = A2*x(t) + B1*x(t) + B2*sat(u(t) – s(t))’;
rule3 = ‘IF f1(t) is "Long" and f2(t) is "Compressed", THEN _x(t) = A3*x(t) + B1*x(t) + B2*sat(u(t) – s(t))’;
rule4 = ‘IF f1(t) is "Short" and f2(t) is "Extended", THEN _x(t) = A4*x(t) + B1*x(t) + B2*sat(u(t) – s(t))’;
% Définition des gains de contrôle
P1 = [1 0 0; 0 1 0; 0 0 1];
P2 = [0 1 0; 0 0 1; 0 0 0];
P3 = [0 0 1; 0 0 0; 0 0 1];
P4 = [1 0 0; 0 1 0; 0 0 1];
% Définition de la fonction de contrôle
control = @(t, x) P1*x + P2*x + P3*sat(u(t) – s(t));
% Simulation
t = 0:0.01:10;
x0 = [1; 0; 0];
u = zeros(size(t));
s = 0.5*t;
z1 = zeros(size(t));
z2 = zeros(size(t));
for i = 1:length(t)
x = x0;
for j = 1:length(t)
if f1(t(j)) > 0.5 && f2(t(j)) > 0.5
x = A1*x + B1*x + B2*sat(u(j) – s(j));
elseif f1(t(j)) < 0.5 && f2(t(j)) < 0.5
x = A2*x + B1*x + B2*sat(u(j) – s(j));
elseif f1(t(j)) > 0.5 && f2(t(j)) < 0.5
x = A3*x + B1*x + B2*sat(u(j) – s(j));
else
x = A4*x + B1*x + B2*sat(u(j) – s(j));
end
end
z1(i) = C1*x;
z2(i) = C2*x;
u(i) = control(t(i), x);
end
% Affichage des résultats
plot(t, z1, t, z2);
xlabel(‘Time (s)’);
ylabel(‘State’);
title(‘Active Suspension System’);
And this the error message ‘ paper1
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of
rows in the second matrix. To perform elementwise multiplication, use ‘.*’.
Error in paper1 (line 42)
x = A2*x + B1*x + B2*sat(u(j) – s(j)); ‘ % Définition des matrices de système
A = [0 0 1 -1 0 0; 0 1 0 0 1 0; 0 0 0 0 0 1];
B1 = [0 1 0; 0 0 0; 0 0 0];
B2 = [0 0 1; 0 0 0; 0 0 0];
C1 = [1 0 0; 0 1 0; 0 0 1];
C2 = [0 0 1; 0 0 0; 0 0 0];
D1 = [1 0 0; 0 1 0; 0 0 1];
% Définition des fonctions d’appartenance floues
f1 = @(t) (t – 0.5)^2;
f2 = @(t) t;
% Définition des règles floues
rule1 = ‘IF f1(t) is "Long" and f2(t) is "Extended", THEN _x(t) = A1*x(t) + B1*x(t) + B2*sat(u(t) – s(t))’;
rule2 = ‘IF f1(t) is "Short" and f2(t) is "Compressed", THEN _x(t) = A2*x(t) + B1*x(t) + B2*sat(u(t) – s(t))’;
rule3 = ‘IF f1(t) is "Long" and f2(t) is "Compressed", THEN _x(t) = A3*x(t) + B1*x(t) + B2*sat(u(t) – s(t))’;
rule4 = ‘IF f1(t) is "Short" and f2(t) is "Extended", THEN _x(t) = A4*x(t) + B1*x(t) + B2*sat(u(t) – s(t))’;
% Définition des gains de contrôle
P1 = [1 0 0; 0 1 0; 0 0 1];
P2 = [0 1 0; 0 0 1; 0 0 0];
P3 = [0 0 1; 0 0 0; 0 0 1];
P4 = [1 0 0; 0 1 0; 0 0 1];
% Définition de la fonction de contrôle
control = @(t, x) P1*x + P2*x + P3*sat(u(t) – s(t));
% Simulation
t = 0:0.01:10;
x0 = [1; 0; 0];
u = zeros(size(t));
s = 0.5*t;
z1 = zeros(size(t));
z2 = zeros(size(t));
for i = 1:length(t)
x = x0;
for j = 1:length(t)
if f1(t(j)) > 0.5 && f2(t(j)) > 0.5
x = A1*x + B1*x + B2*sat(u(j) – s(j));
elseif f1(t(j)) < 0.5 && f2(t(j)) < 0.5
x = A2*x + B1*x + B2*sat(u(j) – s(j));
elseif f1(t(j)) > 0.5 && f2(t(j)) < 0.5
x = A3*x + B1*x + B2*sat(u(j) – s(j));
else
x = A4*x + B1*x + B2*sat(u(j) – s(j));
end
end
z1(i) = C1*x;
z2(i) = C2*x;
u(i) = control(t(i), x);
end
% Affichage des résultats
plot(t, z1, t, z2);
xlabel(‘Time (s)’);
ylabel(‘State’);
title(‘Active Suspension System’);
And this the error message ‘ paper1
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of
rows in the second matrix. To perform elementwise multiplication, use ‘.*’.
Error in paper1 (line 42)
x = A2*x + B1*x + B2*sat(u(j) – s(j)); ‘ matlab, matrix, optimization MATLAB Answers — New Questions