Energy storage optimisation problem - separate charge and discharge constraint
Show older comments
Hi
I'm currently working on an optimization problem to minimize the cost of energy dispatch where we have solar generation and energy storage system. My fmincon function is working, however after i added the constraints for the battery charging and discharging I'm getting an error :
Unable to perform assignment because value of type 'optim.problemdef.OptimizationExpression' is not convertible to 'double'.
Caused by:
Error using double
Conversion to double from optim.problemdef.OptimizationExpression is not possible.
Failure in initial nonlinear constraint function evaluation. FMINCON cannot continue.
I'm not sure what is causing the issue, any help would be great in fixing this.
options = optimoptions('fmincon',...
'Algorithm','sqp','Display', 'iter', 'ConstraintTolerance', 1e-10);
[p, C] = fmincon (@myfun, p0, [], [], [], [], lb, ub, @mycon, options);
% Cost Function that needs to be minimized..
function C = myfun (p)
C =0;
for t = 1:24
for i = 1:4
cost = ce(i) + b(i)*p(t,i) + a(i)*p(t,i)^2;
C = C + cost;
end
end
end
function [c, ceq] = mycon(p) % function [ceq] = mycon(p) in Octave
global Pd P_solar
N= 24;
dt = 1;
BattEnergy = 650;
Einit = 0.5 * BattEnergy;
Emax = 0.8*BattEnergy;
Emin = 0.2*BattEnergy;
Pch = optimvar('Pch',N,'LowerBound',0,'UpperBound',Emax);
Pdisch = optimvar('Pdisch',N,'LowerBound',0,'UpperBound',Emin);
c =0;
c1 =zeros(24,1);
c2 =zeros(24,1);
c3 =zeros(24,1);
c4 =zeros(24,1);
c5 =zeros(24,1);
c6 =zeros(24,1);
for t = 1:24
c1(t) = ( 0 - Pdisch(t));
c2(t) = ( Pdisch(t) - Pdischmax(t));
c3(t) = ( 0 - Pch(t));
c4(t) = ( Pch(t) - Pchmax(t));
c5(t) = Emin - (sum(Pch(t) - Pdisch(t)) * dt) ;
c6(t) = (sum(Pch(t) - Pdisch(t)) * dt) - Emax;
end
c = [c1;c2;c3;c4;c5;c6];
c=c(:);
ceq=0;
for t = 1:24
ceq1(t) = Pch(t) * Pdisch(t);
ceq2(t) = sum(Pch(t) - Pdisch(t)) * dt;
ceq3(t) = sum(p(t,:)) + Pdisch(t) - Pch(t) - Pd(t);
ceq = [ceq1;ceq2;ceq3];
ceq=ceq(:);
end
end
1 Comment
Iñigo Azpiri
on 25 Jan 2022
Dear Hussain,
Could you share the code with the solution you reached? I am also trying to solve a similar problem.
Thanks,
Iñigo
Accepted Answer
More Answers (0)
Categories
Find more on Problem-Based Nonlinear Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!