showing "too many output arguments" error in this code

조회 수: 1 (최근 30일)
KEERTHANA P B
KEERTHANA P B 2022년 1월 25일
답변: ag 2023년 11월 3일
function [J] = pid_optim(x)
s = tf('s');
plant = 1 / (s^2 + 10*s + 20);
Kp = x(1);
Ki = x(2);
Kd = x(3);
cont = Kp + Ki/s + Kd * s;
step(feedback(plant*cont,1));
dt = 0.01;
t = 0:dt:1;
e = 1 - step(feedback(plant*cont,1),t);
J = sum(t'.*abs(e)*dt);

답변 (1개)

ag
ag 2023년 11월 3일
Hi Keerthana,
I understand that you are getting “too many output arguments” error while implementing genetic algorithm.
I tried to run the function provided by you, and it ran without any errors. Try to modify the caller function to rectify the error.
Below is the full working code:
s = tf('s');
Gp = 1 / (s^2 + 10*s + 20);
step(Gp, 2), grid on
nvars = 3;
K = ga(@pid_optim, nvars)
Gc = K(1) + K(2)/s + K(3)*s; % ideal type
Gcl = feedback(Gc*Gp, 1);
step(Gcl, 2), grid on
S = stepinfo(Gcl)
function [J] = pid_optim(x)
s = tf('s');
plant = 1 / (s^2 + 10*s + 20);
Kp = x(1);
Ki = x(2);
Kd = x(3);
cont = Kp + Ki/s + Kd * s;
%step(feedback(plant*cont,1));
dt = 0.01;
t = 0:dt:1;
e = 1 - step(feedback(plant*cont,1),t);
J = sum(t'.*abs(e)*dt);
end
Please refer to the below resources for more details:
Hope this helps!
Best Regards,
Aryan Gupta

카테고리

Help CenterFile Exchange에서 PID Controller Tuning에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by