# matlab中fmincon函数的使用

fmincon是用于求解非线性多元函数最小值的matlab函数。其语法格式比较多，参数也是各有各的意思，我就举几个例子，大家可从代码中去体会其使用方法。

• 示例一

%% 只是大概写个板式，这里的fun2和fun3要自己去定义，这里就不写出来了，前面
%有介绍过
clc
clear
A=[3 2 1;1 2 3; 2 0 0;0 3 0;0 0 2]
b=[120;80;96;102;40]
lb=zeros(3,1)
x0=[1;1;1]
[X fval]=fmincon(@fun3,x0,A,b,[],[],lb,[])
x0=[1;1];
A=[2 3 ;1 4]; b=[6;5];
Aeq=[];beq=[];
VLB=[0;0]; VUB=[];
[x,fval]=fmincon('fun2',x0,A,b,Aeq,beq,VLB,VUB)

• 示例二
%%开始采用默认设置
options = optimoptions('fmincon');
%% 修改参数设置
options = optimoptions(options,'Display', 'off');
options = optimoptions(options,'Algorithm', 'sqp');



%% Start with the default options
options = optimoptions('fmincon');
%% Modify options setting
options = optimoptions(options,'Display', 'off');
options = optimoptions(options,'Algorithm', 'sqp');
fmincon(@fun3,x0,Aineq,bineq,[],[],lb,[],[],options);

• 示例四
%% Start with the default options
options = optimoptions('fmincon');
%% Modify options setting
options = optimoptions(options,'Display', 'off');
options = optimoptions(options,'Algorithm', 'sqp');
fmincon(@fun3,x0,Aineq,bineq,[],[],lb,[],[],options);


• 示例五

%%开始采用默认设置
options = optimoptions('fmincon');
%% 修改参数设置
options = optimoptions(options,'Display', 'off');
options = optimoptions(options,'Algorithm', 'sqp');
fmincon(@fun3,x0,Aineq,bineq,[],[],lb,[],[],options);


• 示例六
function [x,fval,exitflag,output,lambda,grad,hessian] = fmincon代码(x0,Aineq,bineq)
%% This is an auto generated MATLAB file from Optimization Tool.

options = optimoptions('fmincon');
%% Modify options setting
options = optimoptions(options,'Display', 'off');
options = optimoptions(options,'Algorithm', 'sqp');
fmincon(@fun3,x0,Aineq,bineq,[],[],[],[],[],options);



05-15 4万+

08-16 2万+
08-06 4737
05-05 2897
11-24 1万+
05-27 1133
11-26 2万+