Error using barrier Objective function is undefined at initial point. Fmincon cannot continue.

Hi, after running my code
R=readmatrix(filename1);
R=R.';
w=readmatrix(filename2);
gamma = 2;
Aeq = ones(1,68);
beq = 1;
lb = zeros(68,1);
ub = ones(68,1);
x0=0.0147*ones(1,68);
u = @(x) 1/(1-gamma)*x.^(1-gamma);
obj = @(x)-sum(u(x*w*R));
x = fmincon(obj,x0,[],[],Aeq,beq,lb,ub);
I recived the following error
Error using barrier
Objective function is undefined at initial point. Fmincon cannot continue.
Error in fmincon (line 824)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =
barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
I run the same code before but with a lees number of data and it works perfectly. Can you please help me what is wrong with my code ?
Thanks in advance
:::: UPDATE
after my discussion with Torsten : here
I reads my data carefully and found the problem with my data

3 Comments

As the volunteer who worked on your Question and posted the Answer:
No, I do not choose to delete the question. You did not hire me as a private consultant, that you could hide the question and answer away after you have received your solution. I volunteered my time on the condition that the question and response would continue to be available indefinitely, for the benefit of anyone who cared to look.
Thanks Walter. I apprecaite the time everyone spend it here to help . I did not want to mislead the reader since my data cause the problem. I tried to accept Torsten answer but I could not
Original question:
Error using barrier Objective function is undefined at initial point. Fmincon cannot continue.
Hi, after running my code
R=readmatrix(filename1);
R=R.';
w=readmatrix(filename2);
gamma = 2;
Aeq = ones(1,68);
beq = 1;
lb = zeros(68,1);
ub = ones(68,1);
x0=0.0147*ones(1,68);
u = @(x) 1/(1-gamma)*x.^(1-gamma);
obj = @(x)-sum(u(x*w*R));
x = fmincon(obj,x0,[],[],Aeq,beq,lb,ub);
I recived the following error
Error using barrier
Objective function is undefined at initial point. Fmincon cannot continue.
Error in fmincon (line 824)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =
barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
I run the same code before but with a lees number of data and it works perfectly. Can you please help me what is wrong with my code ?
Thanks in advance

Answers (1)

Your gamma is 2. 1-gamma is -1. x.^(1-gamma) is then 1./x
But you permit x to start at 0 (your lower bound is 0). That would get you infinity or nan, either of which is going to cause your objective to fail.
Your lb needs to be greater than 0.

8 Comments

Thanks. I tried to set
lb = 0.2*ones(68,1);
but I received the same error. I changed gamma to be 5 and still the error showing. Any advice is highly appreciated
Test why fmincon has problems evaluating your objective function by calling it before calling fmincon:
R=readmatrix(filename1);
R=R.';
w=readmatrix(filename2);
gamma = 2;
Aeq = ones(1,68);
beq = 1;
lb = zeros(68,1);
ub = ones(68,1);
x0=0.0147*ones(1,68);
u = @(x) 1/(1-gamma)*x.^(1-gamma);
obj = @(x)-sum(u(x*w*R));
obj(x0)
What does obj(x0) return ? Something senseful ?
I am running 270 files in this code . obj(x0) from file 1 to 80 returns Inf. the rest return numbers
Then try in steps.
Evaluate x0*w*R, then u(x0*w*R), then sum(u(x0*w*R)).
And look what you read in as R and w.
I evaluated x0*w*R and u(x0*w*R) then sum(u(x0*w*R)). the result of
sum(u(x0*w*R)) is 374.77477.
I used the code with different problem that has different number of variables and x0 and the code worked . I evaluated x0*w*R and u(x0*w*R) then sum(u(x0*w*R)) for probIem 2( the one that has been solved) and all the reults were at the same format
I modified my code and re-evaluate my objective function at x0 before I call fmincon , it returns a number : -374.623
but still when I run fmincon I received the same error
Error using barrier
Objective function is undefined at initial point. Fmincon cannot continue.
Error in fmincon (line 824)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Then nobody will be able to help you without having access to your data and your complete code.

This question is locked.

Categories

Tags

Asked:

on 13 Apr 2023

Locked:

on 5 Jun 2024

Community Treasure Hunt

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

Start Hunting!