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

3 views (last 30 days)
Hi everyone, is there anyone who could help me solve this problem? I wrote two scripts one with the objective function, the other with the constraint.
function f =heartfitconstraint(cf)
sigex1 = [.0717 .4400 1.3794 3.0752 5.6604 9.2419 13.9150 19.7711];
sigex2 = [.0717 .4400 1.3794 3.0752 5.6604 9.2419 13.9150 19.7711];
lam1 =[0.0579130000000000;0.0577940000000000;......;0.0577940000000000;0.0579130000000000;0.0665110000000000;607;0.0577940000000000]
lam2 = lam1
f = [0.0]
for i = 1:1243
for m = 1:8
f = f + ((1+lam1(i)^2)*(((-1+sqrt((1+lam1(i)^2))*cf(1))/sqrt((1+lam1(i)^2)))+(-1+sqrt((1+lam1(i)^2)))*cf(3)/sqrt((lam1(i)^2+1)))*cf(4)*exp((-1+sqrt((lam1(i)^2+1))^2*cf(1)+(-1+sqrt((1+lam2(i)^2))^2*cf(2))+2*(-1+sqrt((1+lam1(i)^2)))*(-1+sqrt((1+lam2(i)^2)))*cf(3)))-sigex1(m))^2+((1+lam1(i)^2)*(((-1+sqrt((1+lam1(i)^2))*cf(1))/sqrt((1+lam1(i)^2)))+(-1+sqrt((1+lam1(i)^2)))*cf(3)/sqrt((lam1(i)^2+1)))*cf(4)*exp((-1+sqrt((lam1(i)^2+1))^2*cf(1)+(-1+sqrt((1+lam2(i)^2))^2*cf(2))+2*(-1+sqrt((1+lam1(i)^2)))*(-1+sqrt((1+lam2(i)^2)))*cf(3)))-sigex2(m))^2
end
end
function [c,ceq] = heartbehconstraint(cf)
lam1 =[0.0579130000000000;0.0577940000000000;......;0.0577940000000000;0.0579130000000000;0.0665110000000000;607;0.0577940000000000]
lam2 = lam1
for i = 1:1243
c(i) = (1+lam1(i)^2)*((-1+sqrt((1+lam1(i)^2))*cf(1))/sqrt((1+lam1(i)^2))+(-1+sqrt((1+lam1(i)^2))).........+2*(-1+sqrt((1+lam1(i)^2)))*(-1+sqrt((1+lam2(i)^2)))*cf(3))))
end
ceq =[];
end
In Optimization Tool I inserted start point [ 0 0 0 0], but gives me the following error: Objective function is undefined at initial point. Fmincon cannot continue. Thank you very much.

Answers (1)

Ameer Hamza
Ameer Hamza on 10 May 2018
In you for loops, you are trying to access the values of lam1 which do not exist. lam1 has 7 elements. So when i become 8 during iterations. The value of lam1(i) does not exist thus your function throws an error. And fmincon() tells you that value of function does not exist. You need to correct your equations to solve the problem.
  2 Comments
Fredic
Fredic on 10 May 2018
The values of lam1 are 1240 I abbreviated them in the post. In the objective equation there are two summations those for i = 1: 1242 which are the lam(), and those m = 1: 8 which are the sigex(). lam 1 has a 1241 * 1 vector, sigex has a 1 * 8.
Ameer Hamza
Ameer Hamza on 10 May 2018
You mentioned that Iam1 is 1241*1 vector but still you are for loop goes from 1:1242. Are you sure this is not the problem? Try running
heartfitconstraint([0 0 0 0])
to see if the function gives a value at this input.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!