The problem is that you are assuming that row 7 of the gen matrix corresponds
to bus 7, which it doesn't. The 14-bus case only has 5 generators, so you are
adding a new one in row 6, but you need to specify the bus number in the
GEN_BUS column.
If you don't need to do it programmatically, the easiest way is probably to
just create a new case file by making a copy of case14.m under a new name and
adding a row to the gen matrix with the appropriate new values, then pass that
file to loadcase. If for some reason you need to do it programmatically, you'd
want to do something like this (with your own parameters for the new gen, of
course) ...
define_constants;
mpc = loadcase('case14');
ng = size(mpc.gen, 1) + 1;
mpc.gen(ng, GEN_BUS:PMIN) = [7 10 0 10 -10 1.01 100 1 20 0];
runpf(mpc);
--
Ray Zimmerman
Senior Research Associate
419A Warren Hall, Cornell University, Ithaca, NY 14853
phone: (607) 255-9645
On Nov 16, 2011, at 2:16 PM, iman wrote:
> Dear All,
>
> I have a quick question about MATPOWER.
>
> From MATPOWER documentation we know if we want to load the 30-bus system
> data from case30.m,increase its real power demand at bus 2 to 30 MW, then run
> an AC optimal power flow with default options, this could be accomplished as
> follows:
>
> >> define_constants;
> >> mpc = loadcase('case30');
> >> mpc.bus(2, PD) = 30;
> >> runopf(mpc);
>
> Now I want to add a 10MW generator to bus 7 and run pf (not opf) for 14 bus
> system so I write:
>
> >> define_constants;
> >> mpc = loadcase('case14');
> >> mpc.gen (7, PG) = 10; //add 10MW to bus 7
> >>mpc.bus (7, BUS_TYPE) = 2; // changes the type of bus 7 to PV
> >> runpf(mpc);
>
> but I recieve this error:
>
> ??? Subscript indices must either be real positive integers or logicals.
>
> Error in ==> ext2int at 230
> gs = ( mpc.gen(:, GEN_STATUS) > 0 & ... %% gen status
>
> Error in ==> runpf at 131
> mpc = ext2int(mpc);
>
> Do u know what is wrong with my code?
>
> Thanks