Failure in initial objective function evaluation. FMINCON cannot continue.

Hi all!
i have a problem with the function Fmincon. I need a vector as a solution, if i simply put fun = @(p)-sum(log(p)); fmincom gives me only a number, then i tried to put every value of the vector as can be seen below but now i have this error message, can someone give me an advice?
fun = @(p) -(log(p(1))+log(p(2))+log(p(3))+log(p(4))+log(p(5))+log(p(6))+log(p(7))+ log(p(8))+log(p(9))+log(p(10)+log(p(11))+log(p(12))+log(p(13))+log(p(14))+log(p(15))+log(p(16))+log(p(17))));
[b, fval,exitflag,output] = fmincon(fun,0.000000000000001,w' * Matr_VarCov * w,0.005^2);
f = f + 1;
SalvaTitoliDaInvestire = ~isnan(ETF(Mese_Primo(1), :));
Index exceeds the number of array elements (1).
Error in
RiskParityOnly_Esercizio2>@(p)(log(p(1))+log(p(2))+log(p(3))+log(p(4))+log(p(5))+log(p(6))+log(p(7))+log(p(8))+log(p(9))+log(p(10)+log(p(11))+log(p(12))+log(p(13))+log(p(14))+log(p(15))+log(p(16))+log(p(17))))
(line 89)
fun = @(p) (log(p(1)) + log(p(2))+
log(p(3))+ log(p(4))+ log(p(5))+
log(p(6))+ log(p(7))+ log(p(8))+
log(p(9))+ log(p(10)+ log(p(11))+
log(p(12))+ log(p(13))+ log(p(14))+
log(p(15))+ log(p(16))+ log(p(17))));
Error in fmincon (line 562)
initVals.f =
feval(funfcn{3},X,varargin{:});
Error in RiskParityOnly_Esercizio2 (line 90)
[b, fval,exitflag,output] =
fmincon(fun,0.000000000000001,w' *
Matr_VarCov * w,0.005^2);
Caused by:
Failure in initial objective function
evaluation. FMINCON cannot continue.

 採用された回答

Matt J
Matt J 2020 年 10 月 13 日

0 投票

You have 17 unknowns but the initial guess that you passed to fmincon is a scalar.

2 件のコメント

Lorenzo Corigliano
Lorenzo Corigliano 2020 年 10 月 13 日
編集済み: Lorenzo Corigliano 2020 年 10 月 13 日
How can I tell fmincon that I don't want a scalar?
Matt J
Matt J 2020 年 10 月 13 日
Your initial guess should be a length17 vector.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeResults, Reporting, and Test File Management についてさらに検索

タグ

質問済み:

2020 年 10 月 12 日

コメント済み:

2020 年 10 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by