What setting and starting point should I use for FMINCON, matlab
1 次查看(过去 30 天)
显示 更早的评论
Currently I have a very simple function that should be minimized subject to some constraints. I am wonder, how can I correctly tune the fmincon settings to get the best minimum with exit Flag 1. This settings will give me exit flag of -2. Here is my Matlab code:
%%Main
lb=[-1e5,-1e5,0];
ub=[1e5,1e5,1e5];
x0 = unifrnd (lb,ub,[1,3]);
options=optimset('display','off','algorithm','sqp');
[x,~,exitflag]=fmincon(@myfun,x0,[],[],[],[],lb,ub,@mycons,options);
disp(['Exit Flag: ', num2str(exitflag)])
%---------------------------
function f=myfun(x)
f=x(2)-4*x(3)^2;
end
%---------------------------
function [c,ceq]=mycons(x)
x1=x(1); x2=x(2); x3=x(3);
N= [20 1]; xp=[12 0.4];
c(1)=((x1-20)/20)^8+((x2-1)/1)^8-1;
ceq(1)=([1,-1]*(([x1 x2]-xp)./N)')+x3.^2;
end
0 个评论
回答(1 个)
Walter Roberson
2016-2-7
Your nonlinear equality ceq can be stated as 1/20*x1-1/5-x2+x3^2 = 0. You can solve this for x1 and substitute that into your nonlinear inequality and your objective function. But your objective function does not use x1, so that means that you can restate your function with one fewer variables, non-nonlinear equality, and a different form of your nonlinear inequality.
Your revised nonlinear inequality becomes (-4/5+x2-x3^2)^8+(x2-1)^8-1 <= 0 . By probing that function a bit you can see that this cannot be true for x3 greater than about 23/16, or for negative x2 or for x2 > 9/5. This gives you much much much tighter bounds to optimize over. Further testing shows me that the lower bound on x2 is above 0.018 but below 0.019
3 个评论
Walter Roberson
2016-2-8
I used a symbolic package to solve (-4/5+x2-x3^2)^8+(x2-1)^8-1 = 0 for x2. That gave me a quartic whose terms were up to degree 16 in x3. I took one root of the quartic and plotted that with respect to x3 up to 1000 or so and saw that it quickly exceeded the upper bound for x2. I then narrowed down the range considerably. After that I made a bunch of mistakes and tried a bunch of values. After that I went back to the above expression and substituted in x3 values and solved what removed for real roots, found the place that real roots disappeared to find an approximate upper bound on x3. Your constraints already established a lower bound of 0 on x3.
To establish that x2 cannot be negative, note that the two parts of (-4/5+x2-x3^2)^8+(x2-1)^8-1 are both to an even power, so they each contribute somewhere between 0 and 1, so their value before being taken to the 8th power must be between -1 and +1. Look at the (x2-1)^8 part and observe that if x2 < 0 then x2-1 must be even more negative than -1 and so (x2-1)^8 would have to contribute even more than 1 to the sum, making it impossible for (-4/5+x2-x3^2)^8+(x2-1)^8-1 <= 0 to hold with real-valued coefficients. So the minimum value for x2 must be 0 or greater.
Actually I miscalculated the upper bound on x2. The upper limit should be the point at which (x2-1) becomes +1, which is x2 = 2. That gives a hard upper bound on x3 of (1/5)*sqrt(30) .
To summarize: the nonlinear constraint forces x2 a bit > 0, x2 <= 2, x3 >= 0, x3 <= sqrt(30)/5
Walter Roberson
2016-2-8
As for your objective function, if you construct a function which is NaN where the constraint is violated and your objective function otherwise, and you plot over x2 in [0,2] and x3 in [0,sqrt(30)/5], then you quickly see that the minimum is at x2 = 1, and tiny bit of computation on the constraint shows that at that point x3 = sqrt(30)/5, right on the boundary. The minimum of the function is -19/5 under those constraints.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!