fmincon error in intial value
Show older comments
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 Comments
Frida Seewald
on 7 Jul 2020
Edited: Frida Seewald
on 7 Jul 2020
Matt J
on 7 Jul 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
Accepted Answer
More Answers (1)
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.
Categories
Find more on Solver Outputs and Iterative Display 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!