The return value of the objective callback function must be a real double scalar.

7 Ansichten (letzte 30 Tage)
Dear friends,
I am trying to do a Mixed Integer Nonlinear Program (MINLP) Optimization problem by using a "BONMIN" toolbox. I have got an error and couldn't find the problem.
This is my code:
clc,clear
a = 1000;
b = 0.05;
h = 1;
c = 8;
i = 0.02;
r = 0.08;
T_0 = 0.06;
m = 0.5;
O = 200;
syms v x t T p k
%theta
theta = 1/(1+m-v);
inner1 = int(theta, 0, x);
outer1 = int(exp(inner1), 0, T);
inner2 = int(theta, t, x);
outer2 = int(int(exp(inner2), t, T), 0, T);
Warning: Unable to check whether the integrand exists everywhere on the integration interval.
outer3 = int(outer1,0,T)
Warning: Unable to check whether the integrand exists everywhere on the integration interval.
outer3 = 
%Objective function
TP = (a*exp(-b*p)/T)*((p-c*(1+i*k)*(1+r*(T-(k+1)*T_0/2)))*outer1-(h+r*h*p)*outer2+r*p*outer3)-O/T
TP = 
f = -TP
f = 
x = sym('x', [3, 1])
x = 
tn= ['fun_1','.m'];
fun_1 = matlabFunction(subs(f, [k, p, T], [x(1),x(2),x(3)]),'file',tn)
fun_1 = function_handle with value:
@fun_1
fun = @(x) fun_1(x(1),x(2),x(3))
fun = function_handle with value:
@(x)fun_1(x(1),x(2),x(3))
nlcon = @(x) x(3)-T_0*x(1);
cl = 0;
cu = Inf;
lb = [1;c;T_0];
ub = [floor(m/T_0);Inf;m];
x0 = [2 12 0.2]';
opts = optimset('display','iter');
xtype = 'ICC';
Opt = opti('fun',fun,'nl',nlcon,cl,cu,'bounds',lb,ub,'xtype',xtype,'x0',x0,'options',opts)%½¨Á¢¶ÔÏó:×¢Òâ°Ñº¯Êý¡¢Ô¼ÊøÌõ¼þ¡¢±ß½ç¡¢±äÁ¿ÀàÐÍ¡¢³õÖµµÈ¶¼°üº¬½øÀ´
Unrecognized function or variable 'opti'.
[x,fval,exitflag,info] = solve(Opt)% Çó½â
The following is the error obtained :
*** Error using Bonmin Matlab interface: ***
The first return value of the objective callback function must be a real double scalar.
Exception of type: IpoptException in file "Unknown File" at line -1:
Exception message: Unknown Exception caught in Ipopt
NLP0012I
Num Status Obj It time Location
NLP0014I 1 FAILED 0 0 0
*** Error using Bonmin Matlab interface: ***
The first return value of the objective callback function must be a real double scalar.
Exception of type: IpoptException in file "Unknown File" at line -1:
Exception message: Unknown Exception caught in Ipopt
NLP0014I 1 FAILED 0 0 0 resolve robustness
*** Error using Bonmin Matlab interface: ***
The first return value of the objective callback function must be a real double scalar.
Exception of type: IpoptException in file "Unknown File" at line -1:
Exception message: Unknown Exception caught in Ipopt
NLP0014I 3 FAILED 0 0 0
Cbc0006I The LP relaxation is infeasible or too expensive

Antworten (1)

Torsten
Torsten am 15 Okt. 2023
Bearbeitet: Torsten am 15 Okt. 2023
Looking at your objective function, it seems it it returns complex values. This will make MATLAB error - you cannot minimize a function that is complex-valued.
  1 Kommentar
国静
国静 am 18 Okt. 2023
Thanks for your reply, I have carefully checked my objective function and redefined it, which has solved the problem. Thanks again!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Nonlinear Optimization finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by