Error: GA function - Too many output arguments
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
pbarros
am 4 Mär. 2018
Kommentiert: Star Strider
am 4 Mär. 2018
Hello, I am trying to use the ga function to obtain the PID controller gains to a step response in order to minimize the IAE (integral of the absolute error) and I am running the code below.The problem is that when I try to use the Optimization Tool, I always get the 'Too many output arguments' error message.
function myFitness(k)
syms s
SP = 1;
G = (2.156/(42.56*s + 1))*exp(-1.005*s)
C = (k(1) + (k(2)/s) + k(3)*s);
H = feedback(G*C,1);
[z,t] = step(SP*H);
error = abs(SP-z(end));
y = integral(error,0,1000)
end
2 Kommentare
Stephen23
am 4 Mär. 2018
@pbarros: how are you calling this fitness function? Please show the complete error message and the code where this error actually occurs.
Akzeptierte Antwort
Star Strider
am 4 Mär. 2018
There are several problems with your code, not the least of which is your invoking the Symbolic Math Toolbox that is inappropriate here.
This should run. I leave it to you to determine that it produces the correct result:
function myFitness(k)
s = tf('s');
SP = 1;
G = (2.156/(42.56*s + 1))*exp(-1.005*s)
C = (k(1) + (k(2)/s) + k(3)*s);
H = feedback(G*C,1);
[z,t] = step(SP*H);
err_fcn = @(z) abs(SP-z(end));
y = integral(err_fcn,0,1000, 'ArrayValued',1)
end
8 Kommentare
Star Strider
am 4 Mär. 2018
As always, my pleasure.
No worries!
A classical control approach may not be the best option here.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!