The opt_model() function is called automatically within opf_setup.m. You should never need to call it yourself. The add_vars, add_constraints and add_costs, should only be called from within callback functions. See Section 6.2-6.5 of the manual for examples.
If you have a very simple addition to the problem, you might just try direct specification (see Section 6.1 of the manual). There is an example around line 185 of t/t_opf_mips.m. -- Ray Zimmerman Senior Research Associate B30 Warren Hall, Cornell University, Ithaca, NY 14853 phone: (607) 255-9645 On Aug 22, 2013, at 11:01 AM, Stefani Belfustony <[email protected]> wrote: > Dear Prof. Zimmerman, > I am about adding user-defined parts to my case, But I am facing some > problems. > Could you please tell me what shall I do about this: > > > >> define_constants > >> mpc = loadcase(case9); > >> mpopt = mpoption('VERBOSE', 0, 'OUT_ALL', 0, 'PF_DC',1,'OPF_ALG_DC',100); > >> om = opf_model(mpc) > >> get_mpc = (mpc) > >> mpc = ext2int(mpc); > >> om = add_vars(om, 'Pg', 1, 100, -inf, inf); > >> om = add_constraints(om, 'vl', [1], -10, 10, {'Pg'}); > >> cp1 = struct('N', [1], 'Cw', [1]); > >> om = add_costs(om, 'usr1', cp1, {'Pg'}); > >> om > > VARIABLES name i1 iN N > ========= ------ ----- ----- ------ > 1: Pg 1 1 1 > var.NS = 1 var.N = 1 > > NON-LINEAR CONSTRAINTS : <none> > > LINEAR CONSTRAINTS name i1 iN N > ================== ------ ----- ----- ------ > 1: vl 1 1 1 > lin.NS = 1 lin.N = 1 > > > COSTS name i1 iN N > ===== ------ ----- ----- ------ > 1: usr1 1 1 1 > cost.NS = 1 cost.N = 1 > > mpc = > version: '2' > baseMVA: 100 > bus: [9x13 double] > gen: [3x21 double] > branch: [9x13 double] > areas: [1 5] > gencost: [3x7 double] > userdata = 1x1 struct array with no fields. > > >> runopf(mpc) > MATPOWER Version 4.1, 14-Dec-2011 -- AC Optimal Power Flow > MATLAB Interior Point Solver -- MIPS, Version 1.0, 07-Feb-2011 > Converged! > Subscripted assignment dimension mismatch. > > Error in int2ext (line 106) > mpc.bus(o.bus.status.on, :) = o.int.bus; > > Error in opf (line 228) > results = int2ext(results); > > Error in runopf (line 96) > [r, success] = opf(casedata, mpopt); > > Thank you so much. > >
