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)

采纳的回答

Matt J
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 个)

类别

Help CenterFile 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!

Translated by