Info

# comparing element in array

1 view (last 30 days)
Mariam Gasra on 30 Mar 2019
Closed: MATLAB Answer Bot on 20 Aug 2021
clc;
clear all
close all
%%%
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< 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
%%
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
if i have vlue of
P =[ 435.2000
255.4601
109.3481 ]
and the range of element a11 from 500 to 600
range of element a12 from 100 to 300
range of element a13 from 100 to 600
i want to compare each element of P with range and replace the element which is not in the limit by zero
if i use this code the first element change to 500 which is the min value of a11
how can i solve this problem

R2015b

### Community Treasure Hunt

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

Start Hunting!

Translated by