由于专业选修的原因,开始在Italy老师的指导下初次认真地使用matlab,但是由于语言原因,往往不能很好理解上课内容,全靠ppt和后期在网上找相关资料,但是还是感受到了matlab这个矩阵编程器的魅力所在,希望以后能进一步学习和多多运用。
使用基因算法进行最优化,matlab的help中带有非线性约束,所以借鉴了:https://wenku.baidu.com/view/4f6ac0ba960590c69ec3764b.html
ObjectiveFunction = @forehand;
nvars = 2;
LB = [-5 -5];
UB = [5 5];
[x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB)
% ConstraintFunction = @backhand;
% [x,fval] = ga( ObjectiveFunction,nvars,[],[],[],[],LB,UB,...ConstraintFunction )
% [x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB, ...ConstraintFunction)
options = optimoptions(@ga,'PlotFcn',{@gaplotbestf,@gaplotmaxconstr}, 'Display','iter');
% options = gaotimeset(@ga,'PlotFcn',{@gaplotbestf,@gaplotmaxconstr}, 'Display','iter');
[x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB,[],options)
使用模拟退火最优化
ObjectiveFunction = @forehand;
X0 = [-5 -5]; % Starting point
[x,fval] = simulannealbnd(ObjectiveFunction,X0)
lb = [-5 -5]; ub = [5 5];
[x,fval,exitFlag,output] = simulannealbnd(ObjectiveFunction,X0,lb,ub);
options = saoptimset('PlotFcns',{@saplotbestx,@saplotbestf,@saplotx,@saplotf});
[x,fval] = simulannealbnd(ObjectiveFunction,X0,lb,ub,options)
使用粒子群优化
ObjectiveFunction = @forehand;
nvars = 2;
LB = [-5 -5];
UB = [5 5];
[x,fval,exitflag,output]= particleswarm(ObjectiveFunction,nvars,LB,UB);
options = optimoptions(@fminunc, 'Display','Iter','MaxIterations',1500);