can nay one help to understand this code

2 ビュー (過去 30 日間)
PRITAM KUMAR NIRALA
PRITAM KUMAR NIRALA 2022 年 7 月 9 日
コメント済み: dpb 2022 年 7 月 9 日
function [bus_sln, flow]= power_flow(Y, bs, ln)
%The program solves load flow equations for a power system
bs(:,3) =bs(:,3)*pi/180; %converting angle form degree to radians
V0 = bs(:,2);
A0 = bs(:,3);
nbs = size(bs,1);
bsl= find(bs(:,10)==1);
bpv = find(bs(:,10)==2);
bpq = find (bs(:,10)==3);
%Active and reactive power specified at PV and PQ buses
PQ = [bs(bpv,4)-bs(bpv,6); bs(bpq,4)-bs(bpq,6); bs(bpq,5)-bs(bpq,7)];
vt0 = [bs(sort([bpv;bpq]),3);bs(bpq,2)];
itrn=1;
while(true)
T= [zeros(size(bpq,1),size(bpq,1)+size(bpv,1))
eye(size(bpq,1))];
V0(bpq) = T*vt0;
T=[eye(size(bpv,1)+size(bpq,1))...
zero(size(bpq,1)+ size(bpv,1),size(bpq,1))];
A0(sort([bpv;bpql])) =T*vt0;

回答 (2 件)

dpb
dpb 2022 年 7 月 9 日
In a reasonable amount of time, undobutedly not other than the obvious that the overall function appears to solve the network state equations and the third column of the input data array is the phase angle.
Beyond that, unless you can get access to the person who wrote the code from wherever you found it, it's probably going to be more effective use of time to just recode something specifcally for your own purposes where you know what your inputs/variables are.
I've not looked, it's possible there's something useful at the File Exchange for the problem that is documented as to how to use it.

Image Analyst
Image Analyst 2022 年 7 月 9 日
I'd ask the original author and let this be a good lesson for you. Don't do like this person did and not give enough comments in the code to explain it. I trust from now on you'll put in comments BEFORE you write the code. Far too many people just write code and then think they'll put in comments later and never do and end up with an indecipherable, alphabet soup mess of a program with non-descriptive one or two letter variable names. I trust from now on you'll put plenty of comment in your own code. For this program, I'd just start tackling it a line at a time adding comments. Here is a start.
% This function solves load flow equations for a power system
function [bus_sln, flow]= power_flow(Y, bs, ln)
% First define some parameters.
% First define bs. It is the bullshit needed by the program.
bs(:,3) =bs(:,3)*pi/180; %converting angle form degree to radians
% Now assign the initial voltage:
V0 = bs(:,2);
% Now initialize A0, which is who-knows-what.
A0 = bs(:,3);
% Now compute the number of rows of bs, using a totally ridiculous
% variable name of nbs instead of some sensible name like "rows".
nbs = size(bs,1);
% Find the first row where the 10'th column of bs is 1.
% Call it something really cryptic and not descriptive like "bsl"
% just to confuse people who try to re-use and understand this code.
bsl= find(bs(:,10)==1);
% etc.
  1 件のコメント
dpb
dpb 2022 年 7 月 9 日
% Now initialize A0, which is who-knows-what.
A0 = bs(:,3);
About the only other variable with a good guess as to which bs is which -- given one can rely on the initial comment that the code solves the load equations for a power system network, one presumes A is current.
The comments otherwise are spot on...

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

カテゴリ

Help Center および File ExchangeStability Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by