Problem using fmincon to find a constrained minimum
古いコメントを表示
Hello,
I have a problem using fmincon to optimize a function. I have an iterative function. my code is:
function [dy,tanbnew,rt]=fresnel_b(h,n2,m,r,F)
i=1
while i<=ceil(m/2)
dy(i)=0;
dytemp=100;
while abs(dy(i)-dytemp)>0.01
dytemp=dy(i);
aprov=atan(r/(F-h/2));
tanbnew(i)=sin(aprov)/(n2-cos(aprov));
dy(i)=h/tanbnew(i);
end
rt(i)=r;
r=r-dy(i);
i=i+1;
end
width=sum(dy(1:end-1))+dy(end)/2;
and
function [c, ceq]=mycon2(h,n2,m,r,F)
i=1;
while i<=ceil(m/2)
dy(i)=0;
dytemp=100;
while abs(dy(i)-dytemp)>0.01
dytemp=dy(i);
aprov=atan(r/(F-h/2));
tanbnew(i)=sin(aprov)/(n2-cos(aprov));
dy(i)=h/tanbnew(i);
end
rt(i)=r;
r=r-dy(i);
i=i+1;
end
width=sum(dy(1:end-1))+dy(end)/2;
c=-dy;
ceq=width-rt(1)/2;
and
clear,close all
format long
n1=1;
n2=1.5;
d=10;
F=20;
m=21;
h=0.1;
j=1;
r=d/2;
i=1;
fun=@(h)(fresnel(h,n2,m,r,F)-d/2);
con=@(h)mycon2(h,n2,m,r,F);
[h,fval]=fmincon(fun,h,[],[],[],[],[],[],con);
When i run the code it find a minimun but it's not right! A warning message appears in the command window
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in feasible directions, to within the default value of the function tolerance, and constraints are satisfied to within the default value of the constraint tolerance.
I don't completly understand thi message, as a consequence i have no idea how to deal with it! Any help would be appreciated. Thanks in advance...
2 件のコメント
Torsten
2015 年 12 月 4 日
Please write the function to be minimized and the constraint you impose in mathematical notation.
Best wishes
Torsten.
Guido Vallerotto
2015 年 12 月 5 日
回答 (1 件)
Alan Weiss
2015 年 12 月 4 日
0 投票
The exit message does not indicate a problem; in fact, it indicates that fmincon arrived at a true local minimum.
Alan Weiss
MATLAB mathematical toolbox documentation
2 件のコメント
Guido Vallerotto
2015 年 12 月 5 日
John D'Errico
2015 年 12 月 5 日
Then you need to use better starting values. Or you need to use a tool that can do global optimization. Fmincon returns only ONE solution. If that solution is a local one (although still greater than the global solution) based on the starting values it was supplied, then it will return the solution that it finds. It cannot know there is a better solution out there.
Think of fmincon as a blind person placed on the surface of the earth, and tasked with finding the lowest spot (I hope you supplied scuba gear.) It can only look at the local neighborhood it is started in, and searches from there. If you put it in the wrong place, the solver will stop in a non-optimal spot, although locally the lowest spot in that area.
カテゴリ
ヘルプ センター および File Exchange で Choose a Solver についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
