Error using fmincon, the function cannot continue
Afficher commentaires plus anciens
Hi, everyone.
I'm trying to optimize a function with 8 optimization variables. I set up initial point and costraints but appears the following error:
"Error using optim.problemdef.OptimizationProblem/solve
Objective function is undefined at initial point. Fmincon cannot continue.
Error in curvatura_V7 (line 75)
[sol,fval,exitflag,output] = solve(prob,x0);"
the code is as follow:
aymax = 5;
V = 70;
deltay = 60;
deltax = 3;
intorno = sqrt(deltax^2+deltay^2);
dmin = 3;
type objfun
rof1 = optimvar('rof1');
rof2 = optimvar('rof2');
rof3 = optimvar('rof3');
rof4 = optimvar('rof4');
sf1 = optimvar('sf1');
sf2 = optimvar('sf2');
sf3 = optimvar('sf3');
sf4 = optimvar('sf4');
obj = fcn2optimexpr(@objfun,rof1,rof2,rof3,rof4,sf1,sf2,sf3,sf4);
prob = optimproblem('Objective',obj);
constr1 = (-aymax / (V/3.6)^2) <= rof1;
prob.Constraints.curvatura1 = constr1;
constr2 = (aymax / (V/3.6)^2) >= rof1;
prob.Constraints.curvatura1 = constr2;
constr3 = (-aymax / (V/3.6)^2) <= rof2;
prob.Constraints.curvatura2 = constr3;
constr4 = (aymax / (V/3.6)^2) >= rof2;
prob.Constraints.curvatura2 = constr4;
constr5 = (-aymax / (V/3.6)^2) <= rof3;
prob.Constraints.curvatura3 = constr5;
constr6 = (aymax / (V/3.6)^2) >= rof3;
prob.Constraints.curvatura3 = constr6;
constr7 = (-aymax / (V/3.6)^2) <= rof4;
prob.Constraints.curvatura4 = constr7;
constr8 = (aymax / (V/3.6)^2) >= rof4;
prob.Constraints.curvatura4 = constr8;
constr9 = sf1 >= 0 ;
prob.Constraints.ascissa1 = constr9;
constr10 = sf1 <= sf2;
prob.Constraints.ascissa1 = constr10;
constr11 = sf2 >= sf1;
prob.Constraints.ascissa2 = constr11;
constr12 = sf2 <= sf3;
prob.Constraints.ascissa2 = constr12;
constr13 = sf3 >= sf1+sf2;
prob.Constraints.ascissa3 = constr13;
constr14 = sf3 <= sf4;
prob.Constraints.ascissa3 = constr14;
constr15 = sf4 >= sf1+sf2+sf3;
prob.Constraints.ascissa4 = constr15;
constr16 = sf4 <= 2*intorno;
prob.Constraints.ascissa4 = constr16;
show(prob)
x0.rof1 = 0;
x0.rof2 = 0;
x0.rof3 = 0;
x0.rof4 = 0;
x0.sf1 = 0;
x0.sf2 = 0;
x0.sf3 = 0;
x0.sf4 = 0;
[sol,fval,exitflag,output] = solve(prob,x0);
Réponse acceptée
Plus de réponses (1)
Tarunbir Gambhir
le 18 Juin 2021
1 vote
The error message says the objective function is not defined at initial point. This means objfun(xo) returns a 'NaN' or errors out (where "objfun" is objective function and "xo" is the initial point). It could be that the initial point does not satisfy all the provided constraints for the objective function. Since you did not provide the 'objfun', I would not be able to help any further.
Anyway, to avoid this error you can simply try choosing a better initial point.
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!