How to update inputs for fmincon

조회 수: 2 (최근 30일)
Dat Tran
Dat Tran 2016년 2월 15일
댓글: Walter Roberson 2023년 2월 3일
Dear all,
How can I update Aeq, beq and pr for every iteration in such a way that: 1st iteration, the fmincon will get pr=pr0,Aeq=Aeq0,beq=beq0 to solve for p, 2nd iteration the input will be pr=p,Aeq=Aeq1,beq=beq1 to solve for p1, 3rd iteration pr=p1,Aeq=Aeq3,beq=beq3....and so on.
I would appreciate any helps!
Thanks,
Dat
function [p,fval] = MC_NT(p0,opts,N,pr0)
if nargin < 7
opts = optimoptions('fmincon','Algorithm','interior-point');
end
M=length(p0);
p0=p0(:);
pr=0.25*ones(M,1);
p=nan(M,N);
fval=nan(1,N);
pr0=0.25*ones(1,N);
for i=1:N
fun=@(p) sum(p.*log(p./pr));
[p(:,i),fval(i)] = fmincon(fun,p0(:),[],[],Aeq,beq,[],[],[],opts);
pr=p(:,i);
end
  댓글 수: 2
Federico Chiodarelli
Federico Chiodarelli 2023년 2월 3일
Hello, I'm actually facing the same problem (I need to update the initial guess at each iteration using the results of the previous one). Can you describe your problem and maybe generalize the solution please? Because the solution Walter Roberson gave seemed very specific for your problem, and I cannot apply it to mine.
It would be very helpful, thank you in advance!
Walter Roberson
Walter Roberson 2023년 2월 3일
Looking back I am no longer sure that what I proposed in 2016 was what was being looked for.
The code I proposed back then was for the case where you wanted to do a series of independent fmincon, each one using a set of parameters known in advance. So for example if you wanted to minimize a system for a starting point of 100 metres altitude, and then minimize again for a starting point of 200 metres altitude, and so on.
In the code I posted back then, the function to be minimized was effectively being updated each iteration according to the previous result -- but within any one call to fmincon(), the function was consistent.
But sometimes when people talk about updating something each iteration, they mean that the first time that fmincon internally updates its record of best-found-so-far that they want to update some of the parameters or constraints, so that the problem being minimized is changing as fmincon proceeds. fmincon() cannot handle that situation. fmincon() is designed in such a way that a call to the objective function with a given guess x, must always return the same result, no matter which iteration it is being called on. fmincon() cannot be used for stocastic systems for example,

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2016년 2월 15일
Change the Aeq,beq to Aeq{i}, beq{i} and pass those cell arrays in to MC_NT as additional parameters.

Dat Tran
Dat Tran 2016년 2월 15일
편집: Walter Roberson 2016년 2월 15일
Thank you so much for the help! I have tried it but the solution is NaN.
Please correct me if I am wrong. As you suggested the function and objective function should be changed as below?
function [p,fval] = MC_NT(p0,opts,N,pr0,Aeq{i},beq{i})
[p(:,i),fval(i)] = fmincon(fun,p0(:),[],[],Aeq{i},beq{i},[],[],[],opts);
Thank you!
Dat
  댓글 수: 1
Walter Roberson
Walter Roberson 2016년 2월 15일
function [p,fval] = MC_NT(p0, N, pr0, Aeq, beq, opts)
if nargin < 6
opts = optimoptions('fmincon','Algorithm','interior-point');
end
M = length(p0);
p0 = p0(:);
pr = 0.25*ones(M,1);
p = nan(M,N);
fval = nan(1,N);
pr0 = 0.25*ones(1,N);
for i = 1:N
fun=@(p) sum(p.*log(p./pr));
[p(:,i), fval(i)] = fmincon(fun, p0(:), [], [], Aeq{i}, beq{i}, [], [], [], opts);
pr = p(:,i);
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by