fmincon error: Caused by: Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.

1 view (last 30 days)
Hello all ,, Hope are well.
How can i fixed this error : " Caused by: Failure in initial user-supplied objective function evaluation. FMINCON cannot continue. "
//////////////////////////////////
Objective function :
function objec = objective(x)
objec = sum(x(1),2);
end
//////////////////////////////////
Non-linear constraints :
function [c,ceq]= nlcon(x,Leaf_state,leaf_Battery,Focus_state,focus_Battery,Tesla_state,tesla_Battery,aa,bb,y,d)
n1=0.55;
n2=0.40;
n3=0.05;
e=10^-10;
c1= Leaf_state(y,d) - leaf_Battery*n1*x(2);
c2= e*leaf_Battery*n1*x(2) - Leaf_state(y,d) ;
c3= Focus_state(y,d) - focus_Battery*n2*x(2);
c4= e*focus_Battery*n2*x(2) - Focus_state(y,d);
c5= Tesla_state(y,d) - tesla_Battery*n3*x(2);
c6= e*tesla_Battery*n3*x(2) - Tesla_state(y,d);
c=[c1;c2;c3;c4;c5;c6];
c7 = x(1)+aa(y,d)+n1*x(2)*x(6)+n2*x(2)*x(7)+n3*x(2)*x(8)-(bb(y,d)+n1*x(2)*x(3)+n2*x(2)*x(4)+n3*x(2)*x(5));
c8 = Leaf_state(y,18) - n1*leaf_Battery ;
c9 = Focus_state(y,18) - n2*focus_Battery;
c10 = Tesla_state(y,18) - n3*tesla_Battery;
ceq=[c7,c8,c9,c10];
end
//////////////////////////////////
Main File :
aa=P_DC; % Output power PV
bb=Loads; % Loads
A=[];
b=[];
Aeq=[];
beq=[];
n1=0.55;
n2=0.40;
n3=0.05;
eff=0.95;
rate_leaf=6600;
rate_focus=3700;
rate_tesla=16500;
% x(1): Grid
% x(2): # of EV
% x(3): Charge of Leaf % x(6): Discharge of Leaf % x(9) : State of charge (SOC) total Leaf
% x(4): Charge of Focus % x(7): Discharge of Focus % x(10): State of charge (SOC) total Focus
% x(5): Charge of Tesla % x(8): Discharge of Tesla % x(11): State of charge (SOC) total Tesla
Leaf_state = SOC_initialy_Leaf ;
Focus_state = SOC_initialy_Focus ;
Tesla_state = SOC_initialy_Tesla ;
%x0=[0,0,0,0,0,0,0,0];
%x(1)=zeros(365,24);
x0=zeros(365,24);
for y=1:365
for d=1:24
if (d>=10 && d<=18)
if aa(y,d) > bb(y,d)
lb=[-inf,0,0,0,0,0,0,0];
ub=[inf,inf,eff*rate_leaf,eff*rate_focus,eff*rate_tesla,0,0,0];
options = optimoptions('fmincon','Algorithm','interior-point','AlwaysHonorConstraints','none');
[x,fval,exit,output] = fmincon(@(x) objective(x,data),x0,A,b,Aeq,beq,lb,ub,@nlcon,options)
Leaf_state(y,d) = n1*x(2)* Leaf_state(y,d-1) + n1*x(2)*x(3);
Focus_state(y,d) = n2*x(2)*Focus_state(y,d-1) + n2*x(2)*x(4);
Tesla_state(y,d) = n3*x(2)*Tesla_state(y,d-1) + n3*x(2)*x(5);
end
if aa(y,d) < bb(y,d)
lb=[-inf,0,0,0,0,0,0,0];
ub=[inf,inf,0,0,0,rate_leaf/eff,rate_focus/eff,rate_tesla/eff];
options = optimoptions('fmincon','Algorithm','interior-point','AlwaysHonorConstraints','none');
[x,fval,exit,output] = fmincon(@(x) objective(x,data),x0,A,b,Aeq,beq,lb,ub,@nlcon,options)
Leaf_state(y,d) = n1*x(2)* Leaf_state(y,d-1) - n1*x(2)*x(6);
Focus_state(y,d) = n2*x(2)*Focus_state(y,d-1) - n2*x(2)*x(7);
Tesla_state(y,d) = n3*x(2)*Tesla_state(y,d-1) - n3*x(2)*x(8);
end
else
if aa(y,d) > bb(y,d)
lb=[-inf,0,0,0,0,0,0,0];
ub=[inf,0,0,0,0,0,0,0];
options = optimoptions('fmincon','Algorithm','interior-point','AlwaysHonorConstraints','none');
[x,fval,exit,output] = fmincon(@(x) objective(x,data),x0,A,b,Aeq,beq,lb,ub,@nlcon,options)
Leaf_state(y,d) = 0;
Focus_state(y,d) = 0;
Tesla_state(y,d) = 0;
end
if aa(y,d) < bb(y,d)
lb=[-inf,0,0,0,0,0,0,0];
ub=[inf,0,0,0,0,0,0,0];
options = optimoptions('fmincon','Algorithm','interior-point','AlwaysHonorConstraints','none');
[x,fval,exit,output] = fmincon(@(x) objective(x,data),x0,A,b,Aeq,beq,lb,ub,@nlcon,options)
Leaf_state(y,d) = 0;
Focus_state(y,d) = 0;
Tesla_state(y,d) = 0;
end
end
end
end
//////////////////////////////////
Thanks
  7 Comments
Moner Hamed
Moner Hamed on 3 Aug 2019
between d = 10 and d = 18 i mean hours here, there is 3 type of Evs in my project with using V2G and G2V for charging and discharging and after that there is no EVs there's , so to be sure i written 0 in that hour
Walter Roberson
Walter Roberson on 4 Aug 2019
Uh huh. So why bother to do the fmincon() in the case that you are going to ignore the result of the fmincon() ?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 3 Aug 2019
function objec = objective(x)
so your function expects one input
[x,fval,exit,output] = fmincon(@(x) objective(x,data),x0,A,b,Aeq,beq
But your anonymous function passes in two variables.
The second of the variables, data, is undefined
  5 Comments

Sign in to comment.

Categories

Find more on Quadratic Programming and Cone Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!