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

How can I tell fmincon that I don't want a scalar?
Your initial guess should be a length17 vector.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Results, 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