clear;
clc;
%% INPUT DATA
input_data = [200 10.0 0.0095 %C1
240 7.0 0.0070 %C2
200 11.0 0.0090 %C3
220 8.5 0.0090 %C4
220 10.5 0.0080]; %C5
%P1 %P2 %P3 %P4 %P5
loss_data = [0.0015 0 0 0 0
0 0.0014 0 0 0
0 0 -0.0001 0 0
0 0 0 0.0009 0
0 0 0 0 -0.0004];
mwlimits = [ 50 200
100 500
50 150
80 300
50 200];
pd=830; %Power Demand
%%
lambda = input ('Enter initial lambda:')
i=1;
while i <= 6
fprintf('ITERATION %d \n\n', i);
p1=(lambda-input_data(1,2))/(2*(input_data(1,3)+(lambda*loss_data(1,1))));
p2=(lambda-input_data(2,2))/(2*(input_data(2,3)+(lambda*loss_data(2,2))));
p3=(lambda-input_data(3,2))/(2*(input_data(3,3)+(lambda*loss_data(3,3))));
p4=(lambda-input_data(4,2))/(2*(input_data(4,3)+(lambda*loss_data(4,4))));
p5=(lambda-input_data(5,2))/(2*(input_data(5,3)+(lambda*loss_data(5,5))));
fprintf('\tP1: %5.4f\n', p1);
fprintf('\tP2: %5.4f\n', p2);
fprintf('\tP3: %5.4f\n', p3);
fprintf('\tP4: %5.4f\n', p4);
fprintf('\tP5: %5.4f\n\n', p5);
% END OF CHECKING LIMITS %
%VERIFYING IF IT MET THE CONDITIONS%
ploss=(loss_data(1,1)*(p1))+(loss_data(2,2)*(p2))+(loss_data(3,3)*(p3))+(loss_data(4,4)*(p4))+(loss_data(5,5)*(p5));
fprintf('\tPloss: %5.4f\n', ploss);
delta_p=pd+ploss-p1-p2-p3-p4-p5;
fprintf('\tDelta P: %5.4f\n', delta_p);
if (delta_p~=0) %General Case%
summation=((input_data(1,3)+(loss_data(1,1)*input_data(1,2)))/(2*(input_data(1,3)+(lambda*loss_data(1,1)))^2))+((input_data(2,3)+(loss_data(2,2)*input_data(2,2)))/(2*(input_data(2,3)+(lambda*loss_data(2,2)))^2))+((input_data(3,3)+(loss_data(3,3)*input_data(3,2)))/(2*(input_data(3,3)+(lambda*loss_data(3,3)))^2))+((input_data(4,3)+(loss_data(4,4)*input_data(4,2)))/(2*(input_data(4,3)+(lambda*loss_data(4,4)))^2))+((input_data(5,3)+(loss_data(5,5)*input_data(5,2)))/(2*(input_data(5,3)+(lambda*loss_data(5,5)))^2));
fprintf('\tSummation: %5.10f\n', summation);
else if (delta_p==0)&& (p1>mwlimits(1,2)) %Start of P1 random
p1=mwlimits(1,2);
fprintf('\tP1 new: %5.4f', p1);
delta_p=pd+ploss-p1-p2-p3-p4-p5;
summation=((input_data(2,3)+(loss_data(2,2)*input_data(2,2)))/(2*(input_data(2,3)+(lambda*loss_data(2,2)))^2))+((input_data(3,3)+(loss_data(3,3)*input_data(3,2)))/(2*(input_data(3,3)+(lambda*loss_data(3,3)))^2))+((input_data(4,3)+(loss_data(4,4)*input_data(4,2)))/(2*(input_data(4,3)+(lambda*loss_data(4,4)))^2))+((input_data(5,3)+(loss_data(5,5)*input_data(5,2)))/(2*(input_data(5,3)+(lambda*loss_data(5,5)))^2));
fprintf('\tSummation: %5.10f\n', summation);
else if (delta_p==0)&& (p1<mwlimits(1,1))
p1=mwlimits(1,1);
fprintf('\tP1 new: %5.4f', p1);
delta_p=pd+ploss-p1-p2-p3-p4-p5;
summation=((input_data(2,3)+(loss_data(2,2)*input_data(2,2)))/(2*(input_data(2,3)+(lambda*loss_data(2,2)))^2))+((input_data(3,3)+(loss_data(3,3)*input_data(3,2)))/(2*(input_data(3,3)+(lambda*loss_data(3,3)))^2))+((input_data(4,3)+(loss_data(4,4)*input_data(4,2)))/(2*(input_data(4,3)+(lambda*loss_data(4,4)))^2))+((input_data(5,3)+(loss_data(5,5)*input_data(5,2)))/(2*(input_data(5,3)+(lambda*loss_data(5,5)))^2));
fprintf('\tSummation: %5.10f\n', summation);
else if(delta_p==0)&&((p1>mwlimits(1,1))&&(p1<mwlimits(1,2)))
p1=p1;
fprintf('\tP1 new: %5.4f', p1);
delta_p=pd+ploss-p1-p2-p3-p4-p5;
summation=((input_data(1,3)+(loss_data(1,1)*input_data(1,2)))/(2*(input_data(1,3)+(lambda*loss_data(1,1)))^2))+((input_data(2,3)+(loss_data(2,2)*input_data(2,2)))/(2*(input_data(2,3)+(lambda*loss_data(2,2)))^2))+((input_data(3,3)+(loss_data(3,3)*input_data(3,2)))/(2*(input_data(3,3)+(lambda*loss_data(3,3)))^2))+((input_data(4,3)+(loss_data(4,4)*input_data(4,2)))/(2*(input_data(4,3)+(lambda*loss_data(4,4)))^2))+((input_data(5,3)+(loss_data(5,5)*input_data(5,2)))/(2*(input_data(5,3)+(lambda*loss_data(5,5)))^2));
fprintf('\tSummation: %5.10f\n', summation);
end
end
end %End of p1 random
if (delta_p==0)&& (p2>mwlimits(2,2)) %Start of P2 random
p2=mwlimits(2,2);
fprintf('\tP2 new: %5.4f', p2);
delta_p=pd+ploss-p1-p2-p3-p4-p5;
summation=((input_data(1,3)+(loss_data(1,1)*input_data(1,2)))/(2*(input_data(1,3)+(lambda*loss_data(1,1)))^2))+((input_data(3,3)+(loss_data(3,3)*input_data(3,2)))/(2*(input_data(3,3)+(lambda*loss_data(3,3)))^2))+((input_data(4,3)+(loss_data(4,4)*input_data(4,2)))/(2*(input_data(4,3)+(lambda*loss_data(4,4)))^2))+((input_data(5,3)+(loss_data(5,5)*input_data(5,2)))/(2*(input_data(5,3)+(lambda*loss_data(5,5)))^2));
fprintf('\tSummation: %5.10f\n', summation);
else if (delta_p==0)&& (p2<mwlimits(2,1))
p2=mwlimits(2,1);
fprintf('\tP2 new: %5.4f', p2);
delta_p=pd+ploss-p1-p2-p3-p4-p5;
summation=((input_data(1,3)+(loss_data(1,1)*input_data(1,2)))/(2*(input_data(1,3)+(lambda*loss_data(1,1)))^2))+((input_data(3,3)+(loss_data(3,3)*input_data(3,2)))/(2*(input_data(3,3)+(lambda*loss_data(3,3)))^2))+((input_data(4,3)+(loss_data(4,4)*input_data(4,2)))/(2*(input_data(4,3)+(lambda*loss_data(4,4)))^2))+((input_data(5,3)+(loss_data(5,5)*input_data(5,2)))/(2*(input_data(5,3)+(lambda*loss_data(5,5)))^2));
fprintf('\tSummation: %5.10f\n', summation);
else if(delta_p==0)&&((p2>mwlimits(2,1))&&(p2<mwlimits(2,2)))
p2=p2;
fprintf('\tP2 new: %5.4f', p2);
delta_p=pd+ploss-p1-p2-p3-p4-p5;
summation=((input_data(1,3)+(loss_data(1,1)*input_data(1,2)))/(2*(input_data(1,3)+(lambda*loss_data(1,1)))^2))+((input_data(2,3)+(loss_data(2,2)*input_data(2,2)))/(2*(input_data(2,3)+(lambda*loss_data(2,2)))^2))+((input_data(3,3)+(loss_data(3,3)*input_data(3,2)))/(2*(input_data(3,3)+(lambda*loss_data(3,3)))^2))+((input_data(4,3)+(loss_data(4,4)*input_data(4,2)))/(2*(input_data(4,3)+(lambda*loss_data(4,4)))^2))+((input_data(5,3)+(loss_data(5,5)*input_data(5,2)))/(2*(input_data(5,3)+(lambda*loss_data(5,5)))^2));
fprintf('\tSummation: %5.10f\n', summation);
end
end
end %End of p2 random
if (delta_p==0)&& (p5>mwlimits(5,2)) %Start of P5 random
p5=mwlimits(5,2);
fprintf('\tP5 new: %5.4f', p5);
delta_p=pd+ploss-p1-p2-p3-p4-p5;
summation=((input_data(1,3)+(loss_data(1,1)*input_data(1,2)))/(2*(input_data(1,3)+(lambda*loss_data(1,1)))^2))+((input_data(2,3)+(loss_data(2,2)*input_data(2,2)))/(2*(input_data(2,3)+(lambda*loss_data(2,2)))^2))+((input_data(3,3)+(loss_data(3,3)*input_data(3,2)))/(2*(input_data(3,3)+(lambda*loss_data(3,3)))^2))+((input_data(4,3)+(loss_data(4,4)*input_data(4,2)))/(2*(input_data(4,3)+(lambda*loss_data(4,4)))^2));
fprintf('\tSummation: %5.10f\n', summation);
else if (delta_p==0)&& (p5<mwlimits(5,1))
p5=mwlimits(5,1);
fprintf('\tP5 new: %5.4f', p5);
delta_p=pd+ploss-p1-p2-p3-p4-p5;
summation=((input_data(1,3)+(loss_data(1,1)*input_data(1,2)))/(2*(input_data(1,3)+(lambda*loss_data(1,1)))^2))+((input_data(2,3)+(loss_data(2,2)*input_data(2,2)))/(2*(input_data(2,3)+(lambda*loss_data(2,2)))^2))+((input_data(3,3)+(loss_data(3,3)*input_data(3,2)))/(2*(input_data(3,3)+(lambda*loss_data(3,3)))^2))+((input_data(4,3)+(loss_data(4,4)*input_data(4,2)))/(2*(input_data(4,3)+(lambda*loss_data(4,4)))^2));
fprintf('\tSummation: %5.10f\n', summation);
else if(delta_p==0)&&((p5>mwlimits(5,1))&&(p2<mwlimits(5,2)))
p5=p5;
fprintf('\tP5 new: %5.4f', p5);
delta_p=pd+ploss-p1-p2-p3-p4-p5;
summation=((input_data(1,3)+(loss_data(1,1)*input_data(1,2)))/(2*(input_data(1,3)+(lambda*loss_data(1,1)))^2))+((input_data(2,3)+(loss_data(2,2)*input_data(2,2)))/(2*(input_data(2,3)+(lambda*loss_data(2,2)))^2))+((input_data(3,3)+(loss_data(3,3)*input_data(3,2)))/(2*(input_data(3,3)+(lambda*loss_data(3,3)))^2))+((input_data(4,3)+(loss_data(4,4)*input_data(4,2)))/(2*(input_data(4,3)+(lambda*loss_data(4,4)))^2))+((input_data(5,3)+(loss_data(5,5)*input_data(5,2)))/(2*(input_data(5,3)+(lambda*loss_data(5,5)))^2));
fprintf('\tSummation: %5.10f\n', summation);
end
end
end %End of p5 random
end
delta_lambda= delta_p/summation;
fprintf('\tDelta Lambda: %5.4f\n', delta_lambda);
lambda= lambda+delta_lambda;
fprintf('The new lambda =');disp (lambda);
i=i+1;
end
谁能帮助我确定为什么它会跳过第二个else-if语句>还是为什么它会跳过更新P5的值?非常感谢!我真的很困惑为什么它不会通过第二个条件。我真的需要这个来工作,但是我不明白为什么会那样。这实际上是一个经济调度问题,我试图在限定范围内更新/固定P5的值。