not enough input arguments in pso
2 次查看(过去 30 天)
显示 更早的评论
i am working on pso for capcity optimization and here is my objective function sometines it give not enough enough input arguments sometimes it gives unefined variable error kindly help the code and the error lines are given below
function [x] = mycost(A ,B , G ,H ,I)
% objective function (minimization)
x = A + B + G + H + I ;
A = [ (p1 * q1) + (p2 * n * m )];
B = [ (20*Z1 * p1' * q1)];
G = [( 20 * m3 * q1)];
H = [( 20 * z2 * p2 * n * m)];
I = [( 20 * m4 * n * m )];
unitpriceofbattery p1 = 0.8 %unit price of battery (initial guesses )
annualdscountratebat Z1 = 0.15 %annual discont rate of battery
unitpriceofsc p2 = 0.75 %unit price off single sc
annualdiscountratesc z2 = 0.1 %annual discount rate of sc
maintainencecostbat m3 = 0.2283 %annual maintainence cost of battery
maintaninencecostsc m4 = 0.011 % annual maintinence cost of sc
numberofseries m = 10
numberofparallel n = 10
end
% constraints (all constraints must be converted into <=0 type)
% if there is no constraints then comments all c0 lines below
function [c1, c2, c3, c4] = constraint( Ic, Is1, Is2, Ismax)
c(1)=Ic(3)<=Is1<=Ismax;% <=0 type constraints chrging constriants of sc
c(2)=Ic(8)<=Is2<=Ismax;% <=0 type constraints dicharging current of sc
c(3)=Ei(w)+Ei(s)-Ei(l)>=q1+q2; % maximum power sulprus
c(4)=Ek(w)+Ek(s)+q1q2>=Ek(l); %maximum power loss process
% defining penalty for each constraint
%for i=1:length(c0)
%if c0(i)>0
%c(i)=1;
%else
%c(i)=0;
end
%end
%penalty=10000; % penalty on each constraint violation
%f=of+penalty*sum(c); % fitness function
%end
function windpower = calcupower(Pw)
avreagewindspeed f(v) = k/c[(V/c)^k-1]*e^-(V/c)^k;
scaleparameter k = (o/V1)^-1086;
shapeparameter c = (V1/t*(1+1/k));
averagewindspeed v1 = (1/n)*symsum(Vi,i,1,n);
speedvariance o = (1/n-1)*symsum((Vi-V1)^2,i,1,n);
gammafunction t(a) = int((y^a-1)(exp^-y),0,inf);
Vc = 3;
Vr = 12;
Pr = 15;
if V<=Vr
V>=Vc;
Pw (v)= pr*V^k-Vc^k/Vr^k-Vc^k;
end
if V<=Vf
V>=Vr;
then
Pw (v) = Pr;
end
if V < Vc;
or
V > Vf;
then
pw = 0;
end
if p(V>=u)
then
exp^-(u/c)^k; %u is any specified value %
end
end
function solarpower = clcusolarenergy (Es)
I = Isc*[{(1-F1)*(exp (v/C2*Voc - 1))}];
F1 = (1-Im/Isc)*exp(-Vm/C2Voc) ;
F2 = (Vm/Voc - 1)/ln(1 - Im/Isc);
Voc = 40;
Isc = 9.2;
Vm = 30;
Im = 9.18
I(ST) = I + I1*(ST);
v(ST) = v + v1*(ST);
I1(ST) = alfa*(T + S/Sstc(Tnor - Tstc) - Tstc) + I(S/1000 - 1) ;
alfa = 5;
beta = 6;
Sstc = 1000;
Tstc = 25;
Tnor = 40;
Rs = 100;
S = 10000;
v2(ST) = - beta*(T + S/Sstc (Tnor - Tstc) - Tstc) - Rs* I1(ST);
Ireal = I(ST)*(1-Tc);
Tc = (a*N^2) - (b*N + C);
% empirical coefficeints
a = 0.0124;
b = 0.27;
c = 1.04;
E(s) = n * Ireal * V(S,T) * Np * Ns * tp; %monthly power generation of pv
n= n1 * n2 * n3 * n4 * n5 ;
n1 = 0.97; % series and parallel factor
n2 = 0.95; % temp loss factor
n3 = 0.93; %shadow loss factor
n4 = 0.8; %charging and discharging loss factor
n5 = 0.95; % transmission and distribution loss factor
N = [0 , 8]; %cloud cover 0 means clr vise versa
% Ns,Np no of pannels in series an parallel
%tp is the local peak sunshine hours
tp = (S * 0.0116);
Ns = 10;
Np = 10;
end
function battery = calcbatterycapacity(q1)
q5 = (Ic * U * tc);
q6 = (Ic * U * td);
q1 = q5 + q6 ;
U = 24;
end
function supercapcitor = calcstorageenergyofsupercapictor (Qu)
C = (n/m) * Cf ;
Qu = (0.5 * m^2 * C) * {(Usmax)^2 - (Usmin)^2};
% usmax&usmin are the maix & min volatages of single sc
% n& m are the series and parallel groups
% cf is capcitance of single sc
end
2 个评论
DGM
2021-4-2
编辑:DGM
2021-4-2
You know you only posted your cost function, and not how you're actually attempting to do PSO, right? Obviously your cost function isn't being called with enough arguments. Possibly because the PSO demo you're using is built around a cost function with a single argument. If that's the case, you could find a way around that issue, but at this point, I can only guess.
I'm assuming you're basing it off this demo?
I have no idea what the rest of these functions are for or how this syntax is supposed to work or where all the undefined variables come from. Again, I can only guess.
scaleparameter k = (o/V1)^-1086;
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle Swarm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!