- https://www.mathworks.com/matlabcentral/answers/640585-ga-algorithm-for-pid-tuning?s_tid=answers_rc1-3_p3_Topic
- https://www.mathworks.com/help/gads/genetic-algorithm-options.html
showing "too many output arguments" error in this code
1 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 PID Controller Tuning 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!