Thanks, it works. I wrote the code as follows:
nb = size(mpc.bus, 1);
ng = size(mpc.gen, 1);
mpc.N = [sparse(nb, 6) speye(nb, 1) sparse(nb, 5) speye(nb, 1) sparse(nb, 9)
speye(nb, 1) sparse(nb, 3) speye(nb, 1)...
sparse(nb,11) speye(nb, 1) sparse(nb, 1) speye(nb, 1) sparse(nb, 7) ...
sparse(nb, 6) speye(nb, 1) sparse(nb, 5) speye(nb, 1) sparse(nb, 9)
speye(nb, 1) sparse(nb, 3) speye(nb, 1)...
sparse(nb,11) speye(nb, 1) sparse(nb, 1) speye(nb, 1) sparse(nb, 7) ...
sparse(nb, 2*ng)];
r_hat=1; %% r
lam=100;
w=50;
mpc.fparm = ones(nb, 1) * [1 r_hat 0 1];
% mpc.fparm();
mpc.Cw = lam * ones(nb, 1);
mpc.H=w^2*speye(nb,nb);
I want to add another objective function to my optimization is it possible?
(e.g, mpc.fparm2 doesn't work)
Ali Mohammadi
Ph.D. Candidate
Electrical & Computer Engineering
Louisiana State University
133 EE building, Baton Rouge, LA 70803
[cid:c87c2bf8-6841-4f03-8c82-d39f08a364b2]<https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fscholar.google.com%2Fcitations%3Fuser%3DySg5z18AAAAJ%26hl%3Den&data=02%7C01%7Camoha39%40lsu.edu%7Cafed59aeb33c45a9c3e008d6dff512ce%7C2d4dad3f50ae47d983a09ae2b1f466f8%7C0%7C0%7C636942641017445763&sdata=KIRy3hlv4sT0iFDRC%2BxeA9QX2NSgG9noP%2BLrmF49ygQ%3D&reserved=0>
[cid:f70eb5af-7faa-4c9d-986e-0c985bc1c708]
<https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.linkedin.com%2Fin%2Fali-mohammadi-8aa98460%2F%3ForiginalSubdomain%3Dir&data=02%7C01%7Camoha39%40lsu.edu%7Cafed59aeb33c45a9c3e008d6dff512ce%7C2d4dad3f50ae47d983a09ae2b1f466f8%7C0%7C0%7C636942641017445763&sdata=3lxyL4rrWZXUqrZFdsajpO4A1YXnhlUpLyYyCBE%2Fjmw%3D&reserved=0>
________________________________
From: [email protected]
<[email protected]> on behalf of Ray Daniel Zimmerman
<[email protected]>
Sent: Monday, March 16, 2020 10:45 AM
To: MATPOWER-L <[email protected]>
Subject: Re: Question regarding adding cost function
The opf_model object (om) is created by opf_setup() which is called
automatically when you execute runopf(). In order to modify it directly using
om.add_quad_cost(), you will need to define a callback function as described in
Chapter 7 of the manual. For a simple addition like this, it may be easier to
just use the legacy cost mechanism described in Section 6.3.3. In that case,
you can do it by simply adding some parameters to mpc. For example, define the
mpc.N matrix to select the voltage magnitudes from the optimization vector x
(i.e. the columns from nb+1 to 2*nb), and mpc.Cw equal to your Cw.
Hope this helps,
Ray
On Mar 12, 2020, at 2:46 PM, Ali Mohammadi
<[email protected]<mailto:[email protected]>> wrote:
Hi,
I want to add a cost function in my objective function. I wrote the code as
follows but I got error please correct me, If my code is wrong (this is just
the code example).
case_name='9';
mpc=loadcase(['case',case_name]);
om=opt_model(mpc);
% test = loadcase('t_case30_userfcns')
% res=runopf(mpc);
mpopt = mpoption('pf.alg', 'FDXB', 'verbose', 2, 'out.all', 0);
om = opf_setup(mpc,mpopt);
% mpc = toggle_reserves(mpc, 'on')
" OutmailID: 124463678, List: 'matpower-l', MemberID: 85971972 SCRIPT: "%
Cw=zeros(9,1);
Q=zeros(9,1);
Cw([5])=1;
om.add_quad_cost('myQcost', Q, Cw, 0, {'Vm'});
" TCL MERGE ERROR ( 03/16/2020 12:45:11 ): "extra characters after close-quote%
mpc = add_userfcn(mpc, 'formulation', om);
runopf(mpc)
Thank you so much
Ali