# If statement didnt work correctly

6 views (last 30 days)
Mariam Gasra on 26 Mar 2019
Commented: Jan on 3 May 2019
If i run the program if p less than min the result must be equal to zero but in this programme the result equal to min can any one correct the program
clc;
unit=input('input the number of unit:');
dP=D;
Bdat1=input('transmission losses considered matrix:');
B=Bdat1;
dB=diag(B);
data1=input('input the data:n a b c min max');
DA=array2table(data1,'V',{'Unit' 'a' 'b' 'c' 'Pl' 'Ph'});
x=max(DA.b);
n=input('insert number of iteration:')
for i=1:n
while abs(dP)>0.00001
P=(x-DA.b)./(2*(DA.c+x*dB));
P=min(P,DA.Ph);
P=max(P,DA.Pl);
dP=D+P'*B*P-sum(P);
x=x+dP*2/(sum(1./DA.c));
end
end
if P<min(P,DA.Ph)
P=0;
P=P+P;
else
P=P;
end
if P>max(P,DA.Pl)
P=0;
P=P+P;
else
P=P;
end
C=DA.a+DA.b.*P+DA.c.*P.*P;
totalCost=sum(C);
display(totalCost);
lamda=x;
display(lamda);
Loss=P'*B*P;
display(Loss);
table(DA.Unit,P,C,'V',{'Unit' 'Power' 'Cost'})
Mariam Gasra on 28 Mar 2019
If I enter the above data i get3 value of P : 435.2, 299.97,130.66 If min of first p =500 Then first p should equal to zero by if statement conditions
For loop it's for number of unit
Jan on 3 May 2019
@Mariam: You still did not mention, what the problem is. Posting a bunch of unclear question might decrease the interest of the forum in reading your questions.

### Categories

Find more on Surface and Mesh Plots 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!