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