# Setting a small case in PowerModels as m file

**URL:** <https://discourse.julialang.org/t/setting-a-small-case-in-powermodels-as-m-file/43821>\
**Category:** Optimization (Mathematical)\
**Created:** [July 28, 2020, 4:47pm UTC](https://discourse.julialang.org/t/setting-a-small-case-in-powermodels-as-m-file/43821 "2020-07-28T16:47:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mayar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mayar/32/16426_2.png) [@mayar](https://discourse.julialang.org/u/mayar)\
**Post date:** [July 28, 2020, 4:47pm UTC](https://discourse.julialang.org/t/setting-a-small-case-in-powermodels-as-m-file/43821/1 "2020-07-28T16:47:08Z")

</div>

hello there,

I want to test a small 3 bus system on PowerModels and I had to modify the case5.m into case3.m since there was no smaller system than 5 bus network  
however I get this error when I run my julia file with the case3.m  
“LoadError: BoundsError: attempt to access 6-element Array{Int64,1} at index [5:24]”  
This is my network ![snap](https://global.discourse-cdn.com/julialang/original/3X/b/4/b4d4c79a53ed38ece8a32224e75b829fb2ef42fb.jpeg)  
and These are the contents of my 3 bus network m file

```julia
function mpc = case3

%% MATPOWER Case Format : Version 2
mpc.version = '2';

%%----- Power Flow Data -----%%
%% system MVA base
mpc.baseMVA = 100;

%% bus data
%	bus_i	type	Pd	Qd	Gs	Bs	area	Vm	Va	baseKV	zone	Vmax	Vmin
mpc.bus = [
	1	3	0	0	0	0	1	1	0	230	1	1.1	0.9;
	2	1	400	250	0	0	1	1	0	230	1	1.1	0.9;
	3	2	0	0	0	0	1	1	0	230	1	1.1	0.9;
	
];

%% generator data
%	bus	Pg	Qg	Qmax	Qmin	Vg	mBase	status	Pmax	Pmin	Pc1	Pc2	Qc1min	Qc1max	Qc2min	Qc2max	ramp_agc	ramp_10	ramp_30	ramp_q	apf
mpc.gen = [
	1	40	0	30	-30	1	100	1	40	0	0	0	0	0	0	0	0	0	0	0	0;
	1	170	0	127.5	-127.5	1	100	1	170	0	0	0	0	0	0	0	0	0	0	0	0;
	3	323.49	0	390	-390	1	100	1	520	0	0	0	0	0	0	0	0	0	0	0	0;
	
];

%% branch data
%	fbus	tbus	r	x	b	rateA	rateB	rateC	ratio	angle	status	angmin	angmax
mpc.branch = [
	1	2	0.02	0.04	0.00712	400	400	400	0	0	1	-30	30;
	1	3	0.01	0.03	0.03126	0	0	0	0	0	1	-30	30;
	2	3	0.0125	0.025	0.01852	0	0	0	0	0	1	-30	30;

];

%%----- OPF Data -----%%
%% generator cost data
%	1	startup	shutdown	n	x1	y1	...	xn	yn
%	2	startup	shutdown	n	c(n-1)	...	c0
mpc.gencost = [
	1	0	0	10	0	0;
	1	0	0	0	0	0;
	1	0	0	50	0	0;
	
];

```

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [July 28, 2020, 5:48pm UTC](https://discourse.julialang.org/t/setting-a-small-case-in-powermodels-as-m-file/43821/2 "2020-07-28T17:48:17Z")

</div>

Please read the first post of [Please read: make it easier to help you - #81](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757/81) and provide a reproducible example, including a simplified version of the code the reproduces the error, and the full text of the error message.

---

<div class="post-metadata">

**Author:** ![ccoffrin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccoffrin/32/400_2.png) [@ccoffrin](https://discourse.julialang.org/u/ccoffrin)\
**Post date:** [July 28, 2020, 6:42pm UTC](https://discourse.julialang.org/t/setting-a-small-case-in-powermodels-as-m-file/43821/3 "2020-07-28T18:42:31Z")

</div>

In the example you give the generator cost information is not following the Matpower specification. Something like this should work,

```julia
mpc.gencost = [
	2	0	0	3	10	0	0;
	2	0	0	3	0	0	0;
	2	0	0	3	50	0	0;
];

```

I can also recomend you have look at, [https://github.com/power-grid-lib/pglib-opf](https://github.com/power-grid-lib/pglib-opf), as a source of high quality transmission network cases.

---

<div class="post-metadata">

**Author:** ![mayar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mayar/32/16426_2.png) [@mayar](https://discourse.julialang.org/u/mayar)\
**Post date:** [July 28, 2020, 6:57pm UTC](https://discourse.julialang.org/t/setting-a-small-case-in-powermodels-as-m-file/43821/4 "2020-07-28T18:57:44Z")

</div>

Thank you @ccoffrin  
I took this link as my reference and put 1 for a linear gen cost function, but I tried yours and it worked…It means choosing a polynomial and teh putting my a coefficient and other coefficents as zero

[Description of caseformat](https://matpower.org/docs/ref/matpower5.0/caseformat.html#:~:text=A%20MATPOWER%20case%20file%20is,%2C%20and%20(optional)%20gencost).
