Error `Failure in user supplied objective function.FMINCON cannot continue.

1 vue (au cours des 30 derniers jours)
Rabia Zulfiqar
Rabia Zulfiqar le 25 Avr 2020
Modifié(e) : Ameer Hamza le 26 Avr 2020
Hi, I getting this error again and again I have tried multiple times but unable to remove this error.
I have created an objective function and non linear constraints in separate files and the rest of the program in another file.Also I have to optimze my objective function on hourly basis so have I have a for loop for that purpose as I am just a beginner so I´m not so sure about it.
KIndly if somebody can help me removing this error and point out my mistake????? Thankyou in advance
Here is my code.
%Objective function
for t=1:24
function [value]=myfun1(x)
c=[20.2 15.8 15.25 14 13.25 13 15.25 15.56 18 21.25 22.4 21.09 21.09 19.12 17.07 15.8 15.5 14.99 18 26.18 28.98 28.6 27.01 23];
p=[0 0 0 0 0 0 0 0.21515 1.18014 1.90857 2.38382 2.73509 2.75139 2.58261 2.55304 2.05157 1.26134 0.62513 0.03344 0 0 0 0 0];
value=x(1)*.c(t)-x(2)*.c(t)-p(t)*.c(t);
end
end
% non linearity constraints
function [c,ceq]=Untitled6(x)
c=[];
ceq=x(1)*x(2);
end
% Code for the rest of the problem
clearvars
for t=1:24
fun{t}= @myfun1;
end
A=[ -1 1;
1 -1;
-sqrt(0.9) 0;
0 -1/sqrt(0.9);
1 0;
0 1];
b=[5;0;-0.2*1.4;0.95*1.4;1;1];
nonlcon=@Untitled6;
Aeq=[];
beq=[];
lb=[0, 0];
ub=[1, 1];
x0=[0 0];
for t=1:24
x(t)=fmincon(@(t) fun{t},x0,A,b,Aeq,beq,lb,ub,nonlcon);
end
x
  6 commentaires
Rabia Zulfiqar
Rabia Zulfiqar le 25 Avr 2020
Ameer Hmaza in my objective function x(1) and x(2) are unknown and p(t) and c(t) are constants. Can you please clarify if this is not the right way to define it then ow can I define my objective function???
Ameer Hamza
Ameer Hamza le 26 Avr 2020
Rabia's comment posted as answer moved here:
Hey Steven this is the full text. The matlab is just mentioning this text which I have already shared above.

Connectez-vous pour commenter.

Réponses (1)

Ameer Hamza
Ameer Hamza le 26 Avr 2020
Modifié(e) : Ameer Hamza le 26 Avr 2020
Here is my guess what you are trying to do in this code. In MATLAB, the piecewise-multiplication is defined as (.*). Also, the equality constraint does not make much sense. For more specific suggestion, please share your optimization problem in mathematical form
clearvars
A=[ -1 1;
1 -1;
-sqrt(0.9) 0;
0 -1/sqrt(0.9);
1 0;
0 1];
b=[5;0;-0.2*1.4;0.95*1.4;1;1];
nonlcon=@Untitled6;
Aeq=[];
beq=[];
lb=[0, 0];
ub=[1, 1];
x0=[0 0];
for t=1:24
x(t,:) = fmincon(@(x) myfun1(x,t),x0,A,b,Aeq,beq,lb,ub,nonlcon);
end
function [value] = myfun1(x,t)
c=[20.2 15.8 15.25 14 13.25 13 15.25 15.56 18 21.25 22.4 21.09 21.09 19.12 17.07 15.8 15.5 14.99 18 26.18 28.98 28.6 27.01 23];
p=[0 0 0 0 0 0 0 0.21515 1.18014 1.90857 2.38382 2.73509 2.75139 2.58261 2.55304 2.05157 1.26134 0.62513 0.03344 0 0 0 0 0];
value=x(1).*c(t)-x(2).*c(t)-p(t).*c(t);
end
function [c,ceq] = Untitled6(x)
c=[];
ceq=x(1)*x(2);
end

Community Treasure Hunt

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

Start Hunting!

Translated by