Failure in initial objective function evaluation. FMINCON cannot continue
3 ビュー (過去 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!