fmincon是用于求出非线性多变量函数最小值的matlab函数。 语法形式很多,参数也有各自的意义。 让我举几个例子。 从代码中可以知道使用方法。
例1%%只是写为板式,这里的fun2和fun3必须自己定义,所以这里不写。 前%为clcclearA=[3 2 1; 1 ) 3; 2 0 0; 0 3 0; 02 ) b=[120; 80; 96; 102; 40 ) lb=zeros (3,1 ) x0=[1; 1; 1 ) [xfval]=fmincon(@fun3,x0,a,b,[],lb,[] ) x0=[1; 1 ); A=[2 3; 1 ); b=[6; 5 ); Aeq=[]; beq=[]; VLB=[0; 0 ); VUB=[]; [x,fval]=fmincon(‘fun2’,x0,a,b,Aeq,beq,VLB,VUB )示例的2 %为默认设置的options=optimoptions );fmincon %%更改参数设置options=optimoptions(options,’ Display ‘,’ off ‘ ); options=optimoptions(options,’ Algorithm ‘,’ sqp ‘ ); options=optimoptions(options,’ GradObj ‘,’ on ‘ ); options=optimoptions(options,’ GradConstr ‘,’ on ‘ ); [x,fval,exitflag,output,lambda,grad,Hessian]=fmincon(@fit1,x0,a,b,Aeq,beq,lb,ub,nonlcon,on )
% % startwiththedefaultoptionsoptions=optim options (‘ fmin con ‘; % % modifyoptionssettingoptions=optim options (选项,’ Display ‘,’ off ‘ ); options=optimoptions(options,’ Algorithm ‘,’ sqp ‘ ); [x,fval,exitflag,output,lambda,grad,Hessian]=.fmincon(@fun3,x0,Aineq,bineq,[],lb,[]示例4 % % % modifyoptionssettingoptions=optim options (选项,’ Display ‘,’ off ‘ ); options=optimoptions(options,’ Algorithm ‘,’ sqp ‘ ); options=optimoptions(options,’ GradConstr ‘,’ on ‘ ); [x,fval,exitflag,output,lambda,grad,Hessian]=.fmincon(@fun3,x0,Aineq,bineq,[],lb,[]例5 % %%更改参数设置options=optimoptions(options,’ Display ‘,’ off ‘ ); options=optimoptions(options,’ Algorithm ‘,’ sqp ‘ ); options=optimoptions(options,’ GradObj ‘,’ on ‘ ); options=optimoptions(options,’ GradConstr ‘,’ on ‘ ); [x,fval,exitflag,output,lambda,grad,Hessian]=.fmincon(@fun3,x0,Aineq,bineq,[],lb,[]示例function [x hessian]=fmincon代码(x0,Aineq,bineq (% thisisanautogeneratedmatlabfilefromoptimizationtool.% % startwithededefaultontion % % modifyoptionssettingoptions=optim options (选项,’ Display ‘,’ off ‘ ); options=optimoptions(options,’ Algorithm ‘,’ sqp ‘ ); [x,fval,exitflag,output,lambda,grad,Hessian]=.fmincon(@fun3,x0,Aineq,bineq,[],]盲目相信别人写的东西