简体   繁体   中英

What setting and starting point should I use for FMINCON, matlab

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

There is no way to know what is the best initial parameter(s) to use. If there was then the same approach would enable you to know what the best parameter set is, in which case you wouldn't need to perform the optimization.

The best you can do is create a grid/set of initial values, run the optimization multiple times starting it at each of the gridded initial values, and then select the best answer from the resulting set.

If you have the Global Optimization Toolbox then there is MultiStart class that will help you do this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM