- 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 view (last 30 days)
Show older comments
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 Comments
Answers (1)
ag
on 3 Nov 2023
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 Comments
See Also
Categories
Find more on PID Controller Tuning in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!