how can i convert my objective function to scalar expression
15 views (last 30 days)
Show older comments
Good day everyone,
Please, i need help and clarification. the script below is part of the code i developed for multi-energy system optimization
%for power genration from PV,WT and conversion equipment
Cinv1=((rcecost*Prce)+(icecost*Pice)+(pvcost*PV)+(pwcost*PW)+(pemcost*Ppemfc)+(sofcost*Psofc)+(mofcost*Pmofc)+(elzcost*Helz)+(BEcost*NOMb));
Cinv2=((TEScost*NOMq)+(ashcost*Qashp)+(gshpcost*Qgshp)+(gbcost*Qgb)+(gbhcost*Qhp)+(CPAC*ACcost)+(CPEC*ECcost)+(HScost*NOMh)+(NOMc*CScost)+(TSA*TScost));
Cinv=(Cinv1+Cinv2)*AF;
%Maintenance and operational cost of equipment
Cm1=rcecost*Prce*rcemc+icecost*Pice*icemc+pvcost*PV*pvmc+pwcost*PW*pwmc+(pemcost*Ppemfc*pemmc)+(sofcost*Psofc*sofmc)+(mofcost*Pmofc*mofmc)+(elzcost*Helz+elzmc)+(TSA*TScost*TSmc);
Cm2=((TEScost*NOMq*TESmc)+(ashcost*Qashp*ashmc)+(gshpcost*Qgshp*gshpmc)+(gbcost*Qgb*gbmc)+(CPAC*ACcost*ACmc)+(CPEC*ECcost*ECmc)+(HScost*NOMh*HSmc)+(NOMc*CScost*CSmc));
Cmain=Cm1+Cm2;
%Operation cost on fuel and gas, electricity import
NGcost=sum(((NG*dt).*Cgas),1); gridcost=sum(((Pgrid*dt).*Cgrid'),1); sellcost=sum(((Psell*dt).*SellingCost),1);
%energy storages degradation cost
EESc1=sum(((Pbdch*dt)*BEdgcost),1)+sum(((Pbch*dt)*BEdgcost),1)+sum(((qch*dt)*TESdgcost),1)+sum(((qdch*dt)*TESdgcost),1);
EESc2=sum(((cch*dt)*CSdgcost),1)+sum(((cdch*dt)*CSdgcost),1)+sum(((h2ch*dt)*HSdgcost),1)+sum(((h2dch*dt)*HSdgcost),1);
Cop=NGcost+gridcost+EESc1+EESc2-sellcost; %annual total operation cost
%replacement cost
rep1=(rcecost*Prce*rcerep)+(icecost*Pice*icerep)+(pvcost*PV*pvrep)+(pwcost*PW*wtrep)+(pemcost*Ppemfc*pemrep)+(sofcost*Psofc*sofrep)+(mofcost*Pmofc*mofrep)+(elzcost*Helz*elzrep)+(BEcost*NOMb*Brep);
rep2=(TEScost*NOMq*TESrep)+(ashcost*Qashp*ashprep)+(gshpcost*Qgshp*gshprep)+(gbcost*Qgb*gbrep)+(gbhcost*Qhp*gbhrep)+(CPAC*ACcost*ACrep)+(CPEC*ECcost*ECrep)+(HScost*NOMh*HSrep)+(NOMc*CScost*CSrep)+(TSA*TScost*TSrep);
Creplacement=(rep1+rep2)*AF;
%Carbon emission cost
Cco2=sum(((NG*dt)*CO2g*cCO2),1)+sum(((Pgrid*dt)*CO2grid*cCO2),1);
%set the objective function
mesprob.Objective=Cinv+Cmain+Cop+Cco2+Creplacement;
%%options for the optimization algorithm, here we set max time it can run
options = cplexoptimset('cplex');
options.display = 'on';
%call the optimization solver to find the best solution
[x, fval, exitflag, output] = cplexmilp(mesprob, 'options',options);
Please the error i am encountering is:
Error using Untitled4 (line 352)
Objective must be a scalar OptimizationExpression or a struct containing a scalar OptimizationExpression.
please, how can i convert the objective function to scalar expression.
Thanks.
2 Comments
Matt J
on 9 Jan 2020
Edited: Matt J
on 9 Jan 2020
There are many ways to convert a vector to a scalar. You can sum the elements of the vector, or multiply them together, or average them... There are endless possibilities. The step you need depends on what objective function you want and what objective you have right now.
NN
on 28 Jul 2021
please see the below objective function,
i got the same error , but confused where i did mistake .Please help
prob.Objective =dt*Price'*PbattupsV +dt*Price'*PbattdchV*Nb_dch1V'+ dt*Price'*PbattchV*Nb_ch1V' ;
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!