while defining the new fitness function for pso i am getting errors
1 view (last 30 days)
Show older comments
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??
0 Comments
Answers (2)
Walter Roberson
on 28 Mar 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.
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!