'Not enough input arguments' when I am defining a function
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I am trying to link SimEvent and the optimization module of MATLAB. For that, I first need to define a function that runs the simulation then call it in the optimization function that I will define later. But I am getting the "not enough arguments" when defining the function. And I cannot fix it! here is my code and the warning:
function obj = SimOpt(vecX)
NumServers = vecX(1);
NumTruck = vecX(2);
set_param('concreting10/Positioning and Unloading','NumberOfServers',num2str(NumServers));
set_param('concreting10/Washing','NumberOfServers',num2str(NumTruck));
simOut = sim('concreting10','SaveOutput','on','OutputSaveName','WaitingTimeInQueue');
z = simOut.get('WaitingTimeInQueue');
waiting = max(z);
cost = [100 200]*vecX';
obj = waiting*1000+cost;
end
-----------------------------------------------------------
Not enough input arguments.
Error in SimOpt (line 31) NumServers = vecX(1);
-------------------------------------------------------
Would appreciate any help.
댓글 수: 0
답변 (2개)
Walter Roberson
2016년 1월 7일
However it is that your routine SimOpt is getting invoked, it is not being passed any inputs. How is your routine getting invoked?
Alan Weiss
2016년 1월 7일
편집: Alan Weiss
2016년 1월 7일
I think that you have a misunderstanding about what intlinprog does. It does NOT minimize nonlinear functions, such as a function that is the result of a simulation. It minimizes a LINEAR function of a variable x, such as
f(1)*x(1) + f(2)*x(2) + ... + f(N)*x(N)
where the f vector is a constant numeric vector. You appear to be attempting to minimize a nonlinear function by passing a function handle @f, and that is why you get an error.
It is possible that you are trying to minimize a nonlinear function while restricting x(1) to be integer-valued. If that is the case, then I recommend that you minimize using fmincon or fminunc with the value of your x(1) variable set manually to various integer values. You can easily program a search over a one-dimensional integer range, especially since it looks like you want x(1) to go from 1 to 10.
Alan Weiss
MATLAB mathematical toolbox documentation
참고 항목
카테고리
Help Center 및 File Exchange에서 Genetic Algorithm에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!