Failure in initial objective function evaluation. FMINCON cannot continue

3 views (last 30 days)
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)

Accepted Answer

Matt J
Matt J on 10 Mar 2017
Edited: Matt J on 10 Mar 2017
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))

More Answers (0)

Categories

Find more on Quadratic Programming and Cone Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!