How to optimize a parameter, influencing the dynamic response of a control system
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
In the following program, I need to optimize the Kc value, so the variable ratio has a value of 4.
Kc=1;
s = tf('s');
G = 1/(s^2 + s + 1) * exp(-0.1 * s); %plant
GCL = feedback(Kc * G, 1); %closed loop response
t = linspace(0, 15);
u = ones(1, length(t));
out = lsim(GCL, u, t); %system response to step
peak = findpeaks(out); %peaks
ratio = (peak(1) - dcgain(GCL)) / (peak(2) - dcgain(GCL)); %Ratio of two first peaks
0 commentaires
Réponses (2)
Aquatris
le 23 Fév 2024
Here is a brute force way:
desired_ratio = 4;
Kc_vec = 0.1:0.01:10; % Kc search range
ratio = NaN(size(Kc_vec)); % initialize ratio vector
% loop through Kc_vec to see what the resulting ratio is for each Kc
for i = 1:length(Kc_vec)
Kc = Kc_vec(i);
s = tf('s');
G = 1/(s^2 + s + 1) * exp(-0.1 * s); %plant
GCL = feedback(Kc * G, 1); %closed loop response
t = linspace(0, 15);
u = ones(1, length(t));
out = lsim(GCL, u, t); %system response to step
peak = findpeaks(out); %peaks
ratio(i) = (peak(1) - dcgain(GCL)) / (peak(2) - dcgain(GCL)); %Ratio of two first peaks
end
tmp = abs(ratio-desired_ratio); % create a 'cost function'
idx = find(tmp==min(tmp));% find index where ratio is 4
figure(1)
plot(Kc_vec,ratio,Kc_vec(idx),ratio(idx),'x')
text(Kc_vec(idx),ratio(idx)+1,sprintf('Kc = %.2f ratio = %.2f',Kc_vec(idx),ratio(idx)));
xlabel('Kc'),ylabel('ratio')
Sam Chak
le 23 Fév 2024
I just wanted to point out that if you use the step() command instead of the lsim() command, the resulting output will be slightly different. However, I cannot provide a definitive answer regarding which of the two commands, step() or lsim(), is more accurate in generating the step response for time-delayed systems at this moment.
On another note, it's beneficial to familiarize yourself with @Aquatris's brute force searching approach as it offers valuable learning opportunities. Moreover, you can apply the methodology in Python as well.
klb = 1; % lower bound
kub = 3; % upper bound
[Kc, fval] = fminbnd(@cost, klb, kub)
s = tf('s');
G = 1/(s^2 + s + 1)*exp(-0.1*s);
GCL = feedback(Kc*G, 1);
t = linspace(0, 15, 1501);
out = step(GCL, t);
u = ones(1, length(t));
out2 = lsim(GCL, u, t);
TL = tiledlayout(2, 2, 'TileSpacing', 'Compact');
nexttile([1 2]);
plot(t, out), hold on
plot(t, out2), grid on, hold off
legend('step', 'lsim', 'location', 'SE')
nexttile([1 1]);
plot(t, out), hold on
plot(t, out2), grid on, hold off
xlim([1.8 2.0]), title('Peak 1')
nexttile([1 1]);
plot(t, out), hold on
plot(t, out2), grid on, hold off
xlim([5.3 5.8]), title('Peak 2')
title(TL, 'Step Responses')
xlabel(TL, 'Time (sec)')
peak = findpeaks(out); % peaks
ratio = (peak(1) - dcgain(GCL))/(peak(2) - dcgain(GCL)) % Ratio of two first peaks
function J = cost(Kc)
s = tf('s');
G = 1/(s^2 + s + 1)*exp(-0.1*s);
GCL = feedback(Kc*G, 1);
t = linspace(0, 15, 1501);
out = step(GCL, t);
peak = findpeaks(out);
ratio = (peak(1) - dcgain(GCL))/(peak(2) - dcgain(GCL));
J = (ratio - 4)^2;
end
Voir également
Catégories
En savoir plus sur Digital Filtering dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

