while defining the new fitness function for pso i am getting errors

조회 수: 1 (최근 30일)
meenakshi
meenakshi 2014년 3월 28일
답변: meenakshi 2014년 3월 28일
while defining a new fitness function for pso
function F = tracklsqnewfit(pid) % Track the output of optsim to a signal of 1
% Variables a1 and a2 are shared with RUNTRACKLSQ
Kp = pid(1);
Ki = pid(2);
Kd = pid(3);
sprintf('The value of interation Kp= %3.0f,Ki= %3.0f, Kd= %3.0f', pid(1),pid(2),pid(3))
% Compute function value
simopt = simset('solver','ode5','SrcWorkspace','Current','DstWorkspace','Current'); % Initialize sim options
[tout,xout,yout] = sim('meenakshipid7',[0 10],simopt);
S=stepinfo(yout,tout);
tr=S.RiseTime;
ts=S.SettlingTime;
tm=S.Overshoot;
sprintf('The value of interation tr=%3.0f,ts=%3.0f', tr,ts)
e=yout-1 ; % compute the error
sprintf('The value of interation e= %3.0f,tm=%3.0f', e,tm)
Y=(1-exp(-.5))*(tm+e)+exp(-.5)*(ts-tr);
F=1/Y;
sprintf('The value of interation Y= %3.0f,F=%3.0f', Y,F)
end
this error exists ..... ??? In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in ==> PSO at 47 current_fitness(i) = tracklsqnewfit(current_position(:,i));
i cannot understand why??

답변 (2개)

Walter Roberson
Walter Roberson 2014년 3월 28일
My speculation would be that the yout output from sim() is a vector. If so then e = yout - 1 would be a vector, and then since e appears in the definition of Y, Y would end up a vector. That would lead to F being a vector. And a vector of values cannot be stored into a single value.
Your function needs to return a scalar.

meenakshi
meenakshi 2014년 3월 28일
should i run a loop then to send individual valuee to function F......if theres ny ther solution please let me know sir

카테고리

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