i have problem using feval function

1 次查看(过去 30 天)
arudhra
arudhra 2014-12-19
回答: Geoff Hayes 2014-12-19
>> 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);

回答(1 个)

Geoff Hayes
Geoff Hayes 2014-12-19
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.

类别

Help CenterFile Exchange 中查找有关 Particle Swarm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by