Error in Objective function is undefined at initial point. Fmincon cannot continue.
3 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Ameer Hamza
2018-5-10
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 个评论
Ameer Hamza
2018-5-10
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!