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

1 visualización (últimos 30 días)
meenakshi
meenakshi el 28 de Mzo. de 2014
Respondida: meenakshi el 28 de Mzo. de 2014
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??

Respuestas (2)

Walter Roberson
Walter Roberson el 28 de Mzo. de 2014
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 el 28 de Mzo. de 2014
should i run a loop then to send individual valuee to function F......if theres ny ther solution please let me know sir

Categorías

Más información sobre Particle Swarm en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by