Commit d4bf6ae6 by dongshufeng

修改range用法

parent fe4a8a35
......@@ -34,7 +34,7 @@ fn make_sbus(baseMVA, bus, gen) {
on = find(slice(gen, [0], [GEN_STATUS-1, GEN_STATUS]) > 0); // which generators are on?
gbus = get_multi(slice(gen, [0], [GEN_BUS-1, GEN_BUS]), on) - 1; // what buses are they at?
ngon = size(on, 0);
Cg = sparse(gbus, range(0, ngon-1), 1, nb, ngon);
Cg = sparse(gbus, range(0, ngon), 1, nb, ngon);
Gp = slice(gen, [0], [PG-1, PG]);
Gq = slice(gen, [0], [PG-1, PG]);
Sbusg = Cg * (get_multi(Gp, on) + c(0,1) * get_multi(Gq, on)) / baseMVA;
......
......@@ -39,8 +39,8 @@ fn make_y_bus(baseMVA, bus, branch) {
// small case
// build Yf and Yt such that Yf * V is the vector of complex branch currents injected
// at each branch's "from" bus, and Yt is the same for the "to" bus end
i = horzcat(range(1,nl),range(1,nl)) - 1; // double set of row indices
j = range(0,nb - 1);
i = horzcat(range(0, nl),range(0, nl)) - 1; // double set of row indices
j = range(0,nb);
Yf = sparse(i, horzcat(f, t), upper, nl, nb);
Yt = sparse(i, horzcat(f, t), lower, nl, nb);
......@@ -51,8 +51,8 @@ fn make_y_bus(baseMVA, bus, branch) {
} else {
// large case running on MATLAB
// build connection matrices
i = range(0,nl-1);
j = range(0,nb-1);
i = range(0, nl);
j = range(0, nb);
Cf = sparse(i, f, ones(nl, 1), nl, nb); // connection matrix for line & from buses
Ct = sparse(i, t, ones(nl, 1), nl, nb); // connection matrix for line & to buses
......
......@@ -6,7 +6,7 @@ fn runpf() {
nb = size(bus, 0);
ng = size(gen, 0);
g_i = slice(gen, [0], [GEN_BUS-1,GEN_BUS]) - 1; // generator bus indices
Cg = sparse(g_i, range(0,ng-1), slice(gen, [0], [GEN_STATUS-1,GEN_STATUS]) > 0, nb, ng); // gen connection matrix
Cg = sparse(g_i, range(0, ng), slice(gen, [0], [GEN_STATUS-1,GEN_STATUS]) > 0, nb, ng); // gen connection matrix
// element i, j is 1 if, generator j at bus i is ON
bus_gen_status = Cg * ones(ng, 1); // number of generators at each bus that are ON
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论