i have problem using feval function
1 view (last 30 days)
Show older comments
>> x(1:7) = randi([4,50],1,7);
d(1:7) = randi([3,5],1,7);
for i = 1 : 7
sum = 0;
w = 1;
sum = sum + w*(x(i) - d(i));
end
f(1) = sum;
for i = 1 : 7
sum = 0;
sum = sum + w*(x(i) - 4);
end
f(2) = sum;
f = f(1) + f(2);
>> a = Particle_Swarm_Optimization (10,2,[4 50;3 5],f,randi(100,50),2,2,2,0.4,0.9,3);
Completed 0 % ...Error using feval
Argument must contain a string or function_handle.
Error in Particle_Swarm_Optimization (line 103)
availability(p,itr)=feval(Food_availability,parameter);
0 Comments
Answers (1)
Geoff Hayes
on 19 Dec 2014
Arudrha - according to the documentation for the PSO at the FEX Particle Swarm Optimization, the fourth input parameter must be a function of one variable. Pramit Biswas' example is of a function that accepts an array input as
function f = funfunc(array)
a=array(1);
b=array(2);
f = a+b ;
end
In your code, you are not passing a handle to a function but are instead passing the scalar value f.
0 Comments
See Also
Categories
Find more on Particle Swarm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!