필터 지우기
필터 지우기

matlab error operands to the || and &amp &amp operators must be convertible to logical scalar values

조회 수: 1 (최근 30일)
clc;
clear all
close all
%%%
unit=input('input the number of unit:');
D=input('input total load :');
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< DA.Pl) | (P > DA.Ph)
P=0;
end
C=DA.a+DA.b.*P+DA.c.*P.*P;
totalCost=sum(C);
display(P);
display(totalCost);
lamda=x;
display(lamda);
Loss=P'*B*P;
display(Loss);
display(C);
display(P);
if i insert the data :Unit=3
Total load=850
Bdat1=[0.00003 0 0;0 0.00009 0;0 0 0.00012]
data1=[1 605 7.92 0.001562 700 800; 2 310 7.785 0.00194 100 400;3 78 7.97 0.00482 50 300]
n=1
i get the value of P=
500.0000
255.4601
109.3481
but i want the the first value of P which is 500 become zero
in general if one P less than min or greater than max set this P=0
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 3월 29일
Which line of code is the error on? You do not have any && or || in the code you posted
Mariam Gasra
Mariam Gasra 2019년 3월 29일
clc;
clear all
close all
%%%
unit=input('input the number of unit:');
D=input('input total load :');
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 < DA.Ph || P > DA.Pl
P = 0;
end
C=DA.a+DA.b.*P+DA.c.*P.*P;
totalCost=sum(C);
display(P);
display(totalCost);
lamda=x;
display(lamda);
Loss=P'*B*P;
display(Loss);
display(C);
display(P);

댓글을 달려면 로그인하십시오.

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2019년 3월 29일
편집: Andrei Bobrov 2019년 3월 29일
Use
P(P< DA.Pl) | (P > DA.Ph) = 0;
instead
if (P< DA.Pl) | (P > DA.Ph)
P=0;
end
  댓글 수: 6
Walter Roberson
Walter Roberson 2019년 3월 29일
Your P is calculated from DA.b and DA.c, both of which are vectors, so your P will be a vector.
It would look to me to make more sense to check to see whether P is within the corresponding range for that element, rather than it being within any of the ranges.
However, I think Andrei's solution of
P(P < DA.Pl | P > DA.Ph) = 0;
should be all that is needed.
You talk about the value of P being 500, but P is going to be a vector, and whether 500 is valid or not would depend upon the row.
Mariam Gasra
Mariam Gasra 2019년 3월 30일
I went p = 0 299.1984 130.6606 Reject first element because its not within the limt

댓글을 달려면 로그인하십시오.


Andrei Bobrov
Andrei Bobrov 2019년 3월 29일
Thanks Walter! My typo.
Use
P((P< DA.Pl) | (P > DA.Ph)) = 0;
instead
if (P< DA.Pl) | (P > DA.Ph)
P=0;
end
  댓글 수: 1
Mariam Gasra
Mariam Gasra 2019년 3월 29일
if i use this code P((P< DA.Pl) | (P > DA.Ph)) = 0;
the value of P=500 but i want it equal zero
if i use P((P> DA.Pl) | (P < DA.Ph)) = 0;
i get all value of P equal zero

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by