フィルターのクリア

Loop for local function:fmincon

1 回表示 (過去 30 日間)
Dat Tran
Dat Tran 2016 年 2 月 15 日
コメント済み: Dat Tran 2016 年 2 月 15 日
Dear all,
I want to make a loop for the code below: every step, I want to update objective function in such a way that pr=p.
I would appreciate any thoughts and helps!
Dat
function [p,fval] = MC_NT(p0,opts)
if nargin < 2
opts = optimoptions('fmincon','Algorithm','interior-point');
end
[p,fval] = fmincon(@Obj,p0,[],[],Aeq1,beq1,[],[],[],opts);
function f= Obj(p)
f = 0;
pr=0.25*ones(1,16);
for i = 1:16
f = f + p(i)*log(p(i))-p(i)*log(pr(i));
end

採用された回答

Matt J
Matt J 2016 年 2 月 15 日
編集済み: Matt J 2016 年 2 月 15 日
Here is the way I would code it. However, because your objective function is just the KL-divergence, it is trivial to see that the minimum occurs at p=pr. In particular, your loop should produce the same result at every iteration.
function [p,fval] = MC_NT(p0,opts,N)
if nargin < 2
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);
for i=1:N
fun=@(p) sum(p.*log(p./pr));
[p(:,i),fval(i)] = fmincon(fun,p0(:),[],[],Aeq1,beq1,[],[],[],opts);
pr=p(:,i);
end
  1 件のコメント
Dat Tran
Dat Tran 2016 年 2 月 15 日
Thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by