Fmincon - Out of memory Error
Show older comments
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 Comments
To optimize responsiveness to your questions, you should Accept-click valid answers to your previous posts, or else reply to those responding to you why their answers are not what you're looking for.
Mathias Dirksmeier
on 23 Jul 2018
If you attach "p", we would be able to run your code and more easily track the cause of the error.
Aside from the error, however, your nonlinear constraint function is non-differentiable at x(i)=0. This violates assumptions of fmincon. You should probably use ga() instead.
Mathias Dirksmeier
on 23 Jul 2018
Mathias Dirksmeier
on 23 Jul 2018
Mathias Dirksmeier
on 23 Jul 2018
Answers (0)
Categories
Find more on Systems of Nonlinear Equations 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!