fmincon - penalty function
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have the following problem:
I have a data set with half-hourly data for gas production and electricity demand. These are now to be brought together via a CHP (with a certain capacity). The produced gas is to be converted into electricity to cover the electricity demand as well as possible. So I am looking for a power P at each point in time.
To do this, I have calculated the deviation between demand and power in an objective function e and then summed it up.
q = fmincon(@(x) obj_func(x,P,demand,z,P_max,V_level,V_initial,V_size,V_proz,production,BHKW_mode,d),x0,[],[],[],[],lb,ub);
function e = obj_func(x,P,demand,z,P_max,V_level,V_initial,V_size,V_proz,production,BHKW_mode,d)
e = (demand - P).^2;
e = sum(e) + sum(d);
This objective function is then to be minimized with fmincon. This is done and at any time I get : P = demand (why should it not be so).
But now my constraint comes into play.
The gas comes first into a storage and if gas is converted into electricity, the storage content becomes smaller by this quantity.
V_level(1) = V_initial + production(1) - P(1);
for i = 2:z
V_level(i) = V_level(i-1) + production(i) - P(i);
end
V_proz = 100*V_level/V_size;
And this storage may never be fuller than 100 % and never emptier than 0 %. I tried to realize this with a penalty function, which is added to e.
for i = 1:z
if V_proz(i) > 100
d(i) = 100000;
elseif V_proz(i) < 0
d(i) = 100000;
else
d(i) = 0;
end
end
But no matter how big I choose the penalty for non-compliance with this condition: Nothing changes in the result, it is not considered by the optimizer at all....
Does anyone have any idea where my error lies or how I can solve it differently?
Thank you for your help, Matthias
0 commentaires
Réponse acceptée
Torsten
le 17 Mar 2022
Modifié(e) : Torsten
le 17 Mar 2022
As far as I can see, you could formulate your problem as
min: sum_i (abs(demand(i)-P(i)))
s.c.
Pmin <= P(i) <= Pmax
0 <= V_level(i) <= V_size
V_level(i) = V_level(i-1) + production(i) - P(i)
If the difference to your former objective
min: sum_i (demand(i)-P(i))^2
is acceptable, this can be formulated as a linear optimization problem in the unknown P and V_level.
Use linprog to solve.
9 commentaires
Plus de réponses (1)
Matt J
le 17 Mar 2022
Problems
(1) The objective function code you've shown appears to depend on everything except the unknown variables x
(2) Assuming V_proz was supposed to be one of the unknowns, your penalty d is a discontinuous function of it.
10 commentaires
Voir également
Catégories
En savoir plus sur Linear Least Squares dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!