Hi, can you help me in finding a solution for the error of last line in this program that deals with ACO. this step is (feval): the error text is ( no enough argument- noting that I have tried diferent functions like "Ackley"- Thanks

function [x,y, minvalue] = AA(func)
% Example [x, y,minvalue] = AA('Foxhole')
clc;
tic;
subplot(2,2,1); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plot 1 draw(func); title([func, ' Function']);
Ant=100; ECHO=200;
step=0.01*rand(1); temp=[0,0];
start1=-100; end1=100; start2=-100; end2=100; Len1=(end1-start1)/Ant; Len2=(end2-start2)/Ant;
for i=1:Ant X(i,1)=(start1+(end1-start1)*rand(1)); X(i,2)=(start2+(end2-start2)*rand(1));
val=feval(func,[X(i,1),X(i,2)]);

3 Comments

I will appreciate that if someone send me a program for solving function by ACO - functions like : Foxholes, Ackley, Booth. Thank you
Hatim - please format the above code so that it is useable. Highlight the code and press the {} Code button.
As for the error message not enough input arguments, what is the signature for func? You are calling feval as
val=feval(func,[X(i,1),X(i,2)]);
passing in a single input vector. Are you sure that it is a vector that func requires and not two separate input parameters?
Thank you, Geoff. Did you mean this? it still doesn't work. thanks. function [x,y, minvalue] = AA(Ackley) x=-2:2; y=x;
clc;
tic;
subplot(2,2,1);
Ant=100; ECHO=200;
step=0.01*rand(1); temp=[0,0];
start1=-100; end1=100; start2=-100; end2=100; Len1=(end1-start1)/Ant; Len2=(end2-start2)/Ant;
for i=1:Ant x(i,1)=(start1+(end1-start1)*rand(1)); x(i,2)=(start2+(end2-start2)*rand(1));
val=feval(Ackley,[x(i,1),x(i,2)]);
T0(i)=exp(-val); end;

Sign in to comment.

 Accepted Answer

Hatim - no, that isn't quite what I meant. Your code should be formatted as follows
function [x,y, minvalue] = AA(Ackley)
x=-2:2;
y=x;
clc;
tic;
subplot(2,2,1);
Ant=100;
ECHO=200;
step=0.01*rand(1);
temp=[0,0];
start1=-100;
end1=100;
start2=-100;
end2=100;
Len1=(end1-start1)/Ant;
Len2=(end2-start2)/Ant;
for i=1:Ant
x(i,1)=(start1+(end1-start1)*rand(1));
x(i,2)=(start2+(end2-start2)*rand(1));
val=feval(Ackley,[x(i,1),x(i,2)]);
T0(i)=exp(-val);
end;
Note the difference in how it appears in this answer versus that in your comment and question.
-------------
The outputs for this function are x, y and minvalue. Your code sets the first two but not minvalue. Given the above code, what should this value be initialized to?
Note there are also a number of intermediate variables that aren't used: ECHO, step, temp, Len1 and Len2. Can they be removed, or do you expect to use them at a later date?
-------------
As for the signature of the input function, changing it from func to Ackley wasn't what I meant. I was wondering what the function signature is for the input functions, and in particular what are the input parameter(s) for these input function. For example, two of the functions that you are using are Foxhole and Ackley. If you were to open these two functions in the MATLAB editor, what would the signatures for each function be
function [whatGoesHere?] = Ackley(whatGoesHere?)
function [whatGoesHere?] = Foxhole(whatGoesHere?)
Can you paste the signatures (like above) for these two functions? The error message not enough input arguments implies that the code is not passing enough input arguments into either function during the feval operation.

5 Comments

thanks for your time. Actually, above is apart of the following code:
Hatim - when you call the AA function, what are you passing in as the first parameter? It should be a function handle. What can you say about this input? In your previously posted code and in the attached AA.m, you have an input parameter called Ackley where you try to do
val=feval(Ackley,[x(i,1),x(i,2)]);
and later, something similar for a function handle - which is undefined in the code! - called foxholes
F1_T=feval(foxholes,[x(i,1),x(i,2)]);
What are the function signatures for these two functions? Do you have the code for these two functions?
Yes, I have the code for Ackley function and Foxhole function. in fact the error message appears early every time ( step 28). so, I think it is not related to other parts. it is the same when I use one function or even just to plot it. thank you
Hatim - if you have the code for the Ackley and Foxhole functions, then can you either attach the code or just copy and paste the function signature for each into a comment?
If you don't understand what I mean by the function signature then please ask, because without investigating what those signatures are, you won't get past the error at line 28.
Hatim, you can thank him by officially "Accepting" his answer, rather than by flagging it for review. I've deleted the flag. Please go ahead and "accept" his answer if it answers your question - it will give him "reputation points."

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!