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 Center および File ExchangePID Controller Tuning についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by