Fmincon - Out of memory Error
1 次查看(过去 30 天)
显示 更早的评论
Dear community,
We are trying to find an optimal solution to an arbitrage problem. That is, we know energy prices for over one year and a battery storage shall charge at low prices and discharge at high prices in order to maximize revenue. The only constraints being storage's capacity and max charge/discharge rates. Unfortunately, since charging and discharging has different efficiency losses this problem has nonlinear constraints. Using the fmincon, I get the following error:
Error using ldl
Out of memory. Type HELP MEMORY for your options.
Error in formAndFactorAugMatrix
Error in formAndFactorAugMatrix
Error in barrier
Error in fmincon (line 798)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Error in EnergyStorageDispatch_v1 (line 66)
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options);
Here is my code:
% General Definitions
p = Data.RAW.Marginal_Prices;
Smax = 13.5;
Pmax = 5;
n = 0.92;
%%Wholesale Arbitrage
fun = @(x)sum(x.*p);
a1(1:length(p)) = 1;
a2(1:length(p)) = -1;
A = [a1; a2]; % Linear inequality constraint: A*x <= b.
b = [Pmax; Pmax];
x0(1:length(p),1) = 1; % Starting solution
Aeq = []; % Linear Equality constraint: Aeq*x = beq
beq = [];
lb = []; % Lower and upper bounds: lb ? x ? ub
ub = [];
options = optimoptions('fmincon','Display','iter','Algorithm','interior-point');
nonlcon = @(x) capacity(x, n, Smax) ; % Nonlinear inequalities or equalities: c(x) ? 0 and ceq(x) = 0
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options);
function [c,ceq] = capacity(x,n,Smax)
E = sqrt(n)*x;
E(x<0) = (1/sqrt(n))*x(x<0);
S = cumsum([Smax/2; E]);
c1 = -S;
c2 = S - Smax;
c = [c1; c2];
ceq = [];
I know there is a more modern approach to this but I am really curious about where exactly the problem is with my code. As I am really new to optimization issues please be patient with me :)
Thank you very much, Mathias
7 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!