Not Enough Input Argument Error
3 views (last 30 days)
Azime Beyza Ari on 16 Mar 2022
Hello everyone, I am trying to solve a problem using optimization toolbox. The solver i am using is Genetic algorithm solver. I do not understand but i am keep getting this error in my objective function section. I am using live editor and there is a local function section and i wrote my objective function there but keep getting this error. My data is showing in the workspace but objective function seem to be not recgonizing any of the data i have. Here is the objective function i wrote. Can you help me to solve it please?
thank you in advance!
PS: I wrote temp becasue it gave me index error before so tried to solve it this way. Now i am having input argument error.
function z = objectivefunct(ai,rij,xij)
for i = 1:36
for j = 1:36
z = (-1)*(ai(i,1)*temp(i,j)*rij(i,j));
Andreas Apostolatos on 16 Mar 2022
Edited: Andreas Apostolatos on 16 Mar 2022
It is yet not clear what kind of error you are receiving, since you have not shared it with us. However I understand that you are trying to use the 'ga' function in MATLAB and, that you pass as first argument a handle to the function 'objectivefunct' you defined above. Please note, that the function handle that represents the objective function to be minimized should "accept a row vector of length nvars and return a scalar value." Please see the following link for more information,
In your case you are trying to pass three arguments to your objective function 'ai', 'rij', 'xij' which is obviously not allowed. If you want to pass additional arguments to your objective function which are defined in your base workspace, then you can use a wrapper, namely,
x = ga(@(ai) objectivefunct(ai,rij,xij), nvars)
What happens here is, that function 'ga' "sees" only a function handle that receives one input argument 'ai' as input (assuming of course that this input argument contains your design variables) while the rest of the arguments are taken by their definitions in the base workspace.
Please note, that this question is already addressed in different threads, among which also in the following one,
I hope this helps.