Fmincon optmization linear equality in a loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Petros Katsoulis
am 11 Jun. 2017
Kommentiert: Petros Katsoulis
am 12 Jun. 2017
Hello everyone,
I have the following optimization problem: I have data on two vectors A and L of size 39x1 each representing in economic terms assets and liabilities of 39 agents. Each agent optimizes his assets and liabilities via an objective function and subject to some constraints. Hence each agent's problem is solved via fmincon which produces a 2x1 vector and I call it 39 times via a loop:
for i=1:39
% Aeq=[1 1];
% Beq=A(i)+L(i);
[x,fval,flag]=fmincon(@objfun,[A(i);L(i)],[],[],[],[],[0;0],[inf;inf],@confun,options);
xx(i,1)=x(1);
xx(i,2)=x(2);
end
D=sum(xx(:,1));
S=sum(xx(:,2));
EG=abs(D-S);
I store each solution to xx which is a 39x2 matrix containing the solutions for all agents. My problem is that I need the sum of xx(:,1) and the sum of xx(:,2) representing total assets and liabilities to be equal to the sum of my original data A and L respectively (which are used as initial values) so sum(D)=sum(A) and sum(S)=sum(L). By construction sum(A)=sum(L). Is there a way to achieve this in this setting? I tried a crude approximation of having each agent's sum of assets and liabilities to be equal to his original sum of A and L via the commented Aeq and Beq linear equalities but it is not a satisfactory answer as I need it to hold only for all of them but not individually necessarily.
Any useful recommendations are greatly appreciated. Thank you.
P.S. in reality this is a nested optimization since I call the function containing this loop in another one that minimizes the output EG (essentially finding the value of a parameter p that makes D=S). I am not sure whether this helps but thought it would be useful to mention.
0 Kommentare
Akzeptierte Antwort
Matt J
am 11 Jun. 2017
Bearbeitet: Matt J
am 11 Jun. 2017
My problem is that I need the sum of xx(:,1) and the sum of xx(:,2) representing total assets and liabilities to be equal to the sum of my original data A and L respectively
If that's the case, then you cannot pose this as 39 separate optimization problems. You have to solve for all xx(i,:) simultaneously. You would probably do this by implementing a new objective function that is the sum of all the individual objectives of the 39 agents. The equality constraint on the totals of xx would be implemented as
Aeq=[ones(1,39),zeros(1,39) ; zeros(1,39),ones(1,39)];
beq=[sum(A);sum(L)];
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!