fmincon error in intial value

3 visualizaciones (últimos 30 días)
Frida Seewald
Frida Seewald el 7 de Jul. de 2020
Editada: Matt J el 7 de Jul. de 2020
Im trying to use fmincon but I can't get rid of this error
Error using barrier
Objective function is undefined at initial point. Fmincon cannot continue.
Error in fmincon (line 834)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =
barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Error in opt_v03 (line 105)
[xopt6,fval6]=fmincon(fun6,x0,Aueq,bueq,Aeq,beq,lb,ub);
These are my Input Values
x0=[0.8,20]; lb=[0.8,15]; ub=[1.5,40];
Aueq=[]; bueq=[]; Aeq=[]; beq=[];
[xopt6,fval6]=fmincon(fun6,x0,Aueq,bueq,Aeq,beq,lb,ub);
fun6 =
function_handle with value:
@(x)(1033.6304-25.9573.*x(1)+271.9537.*x(2)-33.6851.*x(1).*x(2)-19.5246.*x(2)^2).^1.5.*(7.3732+0.048178.*x(1)+0.28244.*x(2)-0.049607.*x(1).*x(2)-0.13446.*x(2)^2)
If i use the command window and type fun6([0.8,15]) it returns a scalar, so I don't understand why MATLAB is telling me the function is undefined. Can anyone please help?
  2 comentarios
Frida Seewald
Frida Seewald el 7 de Jul. de 2020
Editada: Frida Seewald el 7 de Jul. de 2020
it seems like for some points my function returns complex doubles, is there a way to surpress this? Also I don't see why my function would return complex numbers..I exchanged the power to 1.5 with 2 but this didn't change anything (i use the 1.5 factor as a weighting factor)
Matt J
Matt J el 7 de Jul. de 2020
I exchanged the power to 1.5 with 2 but this didn't change anything (i use the 1.5 factor as a weighting factor)
The complex numbers definitely come from the power of 1.5. Changing it to 2 should fix it, and does indeed do so when I run the code:
>> [xopt6,fval6]=fmincon(fun6,x0,Aueq,bueq,Aeq,beq,lb,ub)
xopt6 =
1.5000 40.0000
fval6 =
-9.1198e+10

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 7 de Jul. de 2020
The ‘fun6’ function produces a purely imaginary result at the initial point. That is throwing the error.
One option is to specify to use only the real result:
[xopt6,fval6]=fmincon(@(x)real(fun6(x)),x0,Aueq,bueq,Aeq,beq,lb,ub);
Other options would be to use the imag() function to return the imaginary result, or the abs() function to return the magnitude of the complex result. It depends on what you want to do.

Más respuestas (1)

Matt J
Matt J el 7 de Jul. de 2020
Editada: Matt J el 7 de Jul. de 2020
You must do something that not only gets rid of complex-valued results, but also respects fmincon's requirement that your objective be twice differentiable. One method which would take care of both problems is to square your objective:
fun6squared = @(x)(1033.6304-25.9573.*x(1)+271.9537.*x(2)-33.6851.*x(1).*x(2)-19.5246.*x(2)^2).^3 ...
.*(7.3732+0.048178.*x(1)+0.28244.*x(2)-0.049607.*x(1).*x(2)-0.13446.*x(2)^2).^2;
[xopt6,fval6]=fmincon(fun6squared,x0,Aueq,bueq,Aeq,beq,lb,ub);
The downside of this, however is that the sub-expression
c(x) = 7.3732+0.048178.*x(1)+0.28244.*x(2)-0.049607.*x(1).*x(2)-0.13446.*x(2)^2
currently has the ability to force your original objective function to go negative. In the modified problem, it can no longer do so, and therefore the location of the optimum might change. Did you even intend for the optimization to include the region c(x)<=0 ? If not, then there is no problem, although you must tell fmincon about the nonlinear constraint c(x)>=0.

Categorías

Más información sobre Solver Outputs and Iterative Display 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