Error: GA function - Too many output arguments

조회 수: 1 (최근 30일)
pbarros
pbarros 2018년 3월 4일
댓글: Star Strider 2018년 3월 4일
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
Stephen23
Stephen23 2018년 3월 4일
@pbarros: how are you calling this fitness function? Please show the complete error message and the code where this error actually occurs.
pbarros
pbarros 2018년 3월 4일
Hi, I created the function so I could use it to obtain the controller gains using the Optimization Tool in which I set the Fitness function to '@myFitness' and the number of variables to '3'. The complete error message that I get from the Optimization Tool when I try to run the solver is the following: ' Optimization running. Error running optimization. Too many output arguments.'
In the command window there is the warning below but I did what it asked and nothing changed.
Warning: You are using 'mutationuniform' mutation function for constrained minimization.
Solution may be infeasible; use '@mutationadaptfeasible' function for constrained minimization.
> In constrValidate (line 76)
In gacommon (line 125)
In ga (line 336)
In callSolver (line 32)
In optimguirun (line 40)
In optimguiswitchyard (line 14)

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2018년 3월 4일
There are several problems with your code, not the least of which is your invoking the Symbolic Math Toolbox that is inappropriate here.
See the documentation for the tf (link) function.
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
pbarros
pbarros 2018년 3월 4일
I am trying to get the best gains values ('k') that minimizes the error function (between the reference signal ('SP') and the step response 'z' function). I must have made a mistake somewhere because I think I should get a very small value for the 'fval'. Thank you for the help and I am sorry for all the confusion.
Star Strider
Star Strider 2018년 3월 4일
As always, my pleasure.
No worries!
A classical control approach may not be the best option here.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by