Failure in initial objective function evaluation. FMINCON cannot continue

3 visualizaciones (últimos 30 días)
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)

Respuesta aceptada

Matt J
Matt J el 10 de Mzo. de 2017
Editada: Matt J el 10 de Mzo. de 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))

Más respuestas (0)

Categorías

Más información sobre Quadratic Programming and Cone Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by