How to repeat whole coding by increasing value of variable

2 ビュー (過去 30 日間)
Lee Dira
Lee Dira 2020 年 6 月 14 日
コメント済み: Aditya Verma 2020 年 6 月 15 日
Hi, i wonder if i can run my coding 5 times but vary my bus_value. I want get value of Ploss, location1, location2, real1,real2, reactive1 and reactive2 automaticly for each load (20, 30, 40, 50 and 60) instead of changing manually the bus_value=30 then run. copy the 'accepted value' into excel. Then change again the bus_value=40. Run again and copy in excel again...until bus_value=60.
bus_no=20; % chosen load bus, Qd20
bus_value=20; %% 20 MVAR, Qd20=20 MVAR (vary 20MVAR to 30-60 MVAR)
for i1=1:20
%caling 30-bus syst
[basemva,accuracy,maxiter,busdata,linedata]=Bus_30;
busdata(bus_no,6)=bus_value; %%% Stress the load
%%fitness 1-inject Pdg & Qdg in 30-syst to find new Ploss
busdata(x1_Dg1(i1),5)=-x1_Pdg1(i1);
busdata(x1_Dg1(i1),6)=x1_Qdg1(i1);
busdata(x1_Dg2(i1),5)=-x1_Pdg2(i1);
busdata(x1_Dg2(i1),6)=x1_Qdg2(i1);
%run loadflow
lfybus;; %forms the bus admittance matrix
lfnewton;; %power flow solution by newton raphson method
busout;; %prints the power flow solution on the screen
linefloww;;
%%%%% FITNESS 1 %%%%%
VminDg1(i1)=min(Vm);
PlossDg1(i1)=real(SLT);
DataF1(i1,:)=[x1_Dg1(i1),x1_Dg2(i1),x1_Pdg1(i1),x1_Pdg2(i1),x1_Qdg1(i1),x1_Qdg2(i1),VminDg1(i1),PlossDg1(i1)];
end
%%% value accepted%%
ploss=DataF1(1,8)
location1=DataF1(1,1)
location2=DataF1(1,2)
real1=DataF1(1,3)
real2=DataF1(1,4)
reactive1=DataF1(1,5)
reactive2=DataF1(1,6)

回答 (1 件)

Aditya Verma
Aditya Verma 2020 年 6 月 14 日
編集済み: Aditya Verma 2020 年 6 月 14 日
Hi, you can use functions to avoid code repetition:
for bus_value = 20:10:60
[ploss, location1, location2, real1, real2, reactive1, reactive2] = myFunction(bus_value);
% Do something with your output
end
If you're new to this concept I would suggest you to try the free MATLAB onramp course, feel free to skip to the section "Calling Functions".
You can read more about functions herehttps://www.mathworks.com/help/matlab/functions.html
  4 件のコメント
Lee Dira
Lee Dira 2020 年 6 月 15 日
Thank you for teaching me. I will try the coding.
Aditya Verma
Aditya Verma 2020 年 6 月 15 日
You're welcome. If you've found this answer helpful and it resolves your doubt, then you can mark it as accepted.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWeb Services についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by