Failure in initial objective function evaluation. FMINCON cannot continue
조회 수: 6 (최근 30일)
이전 댓글 표시
I have issues with the fmincon function. I am trying to minimize the average absolute difference between a function and a set of values by changing five parameters of the function. The constraints are that the parameters have a lower and upper bound and a nonlinear constraint that I specified in a myconstraint function. I keep getting an error message that the initial objective function could not be evaluated. My code is shown below. Can someone please help me
AbsError = @(x1,x2,x3,x4,x5) mean(sum(abs(cp(x1,x2,x3,x4,x5)- Prices)));
par0 =[0.1, 0.1, 0.1, 0.1, 0.1];
lb = [0, 0, 0, 0, -1];
ub = [10, 10, 10, 10, 1];
nonlcon = @myconstraint;
X1 = fmincon(AbsError,par0,[],[],[],[],lb,ub,nonlcon)
댓글 수: 0
채택된 답변
Matt J
2017년 3월 10일
편집: Matt J
2017년 3월 10일
Rewrite your function to have a single vector input argument
AbsError = @(p) mean(sum(abs(cp(p(1),p(2),p(3),p(4),p(5))- Prices)));
Also, test AbsError and make sure it returns a value successfully before feeding it to fmincon.
Finally, beware non-smooth functions like abs() which introduce non-differentiability. Maybe use a quadratic error function instead,
mean(sum((cp- Prices).^2))
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Quadratic Programming and Cone Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!