MATLAB求解非线性规划问题 10
minf(x)=(x(1)-2)^2+(x(2)-3)^2s.tx(1)^2+(x(2)-2)^2>=4x<=2(2)...
min f(x)=(x(1)-2)^2+(x(2)-3)^2
s.t x(1)^2+(x(2)-2)^2>=4
x<=2(2) 展开
s.t x(1)^2+(x(2)-2)^2>=4
x<=2(2) 展开
1个回答
展开全部
先在MATLAB编辑器中建立非线性约束函数文件:
function [c,ceq]=my(x)
c=4-x(1)^2-(x(2)-2)^2;
ceq=[];
另存为my.m
在命令窗口键入如下命令:
>> fun='(x(1)-2)^2+(x(2)-3)^2';
>> [x,fval,exitflag,output,lambda]=fmincon(fun,rand(2,1),[],[],[],[],[],[inf;2],@my)
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In fmincon at 260
Optimization terminated: first-order optimality measure less than options.TolFun
and maximum constraint violation is less than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
2
x =
2.0000
2.0000
fval =
1.0000
exitflag =
1
output =
iterations: 5
funcCount: 23
stepsize: 1
algorithm: 'medium-scale: SQP, Quasi-Newton, line-search'
firstorderopt: 3.8545e-013
cgiterations: []
message: [1x143 char]
lambda =
lower: [2x1 double]
upper: [2x1 double]
eqlin: [0x1 double]
eqnonlin: [0x1 double]
ineqlin: [0x1 double]
ineqnonlin: 2.2352e-007>> fun='(x(1)-2)^2+(x(2)-3)^2';
>> [x,fval,exitflag,output,lambda]=fmincon(fun,rand(2,1),[],[],[],[],[],[inf;2],@my)
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In fmincon at 260
Optimization terminated: first-order optimality measure less than options.TolFun
and maximum constraint violation is less than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
2
x =
2.0000
2.0000
fval =
1.0000
exitflag =
1
output =
iterations: 5
funcCount: 23
stepsize: 1
algorithm: 'medium-scale: SQP, Quasi-Newton, line-search'
firstorderopt: 3.8545e-013
cgiterations: []
message: [1x143 char]
lambda =
lower: [2x1 double]
upper: [2x1 double]
eqlin: [0x1 double]
eqnonlin: [0x1 double]
ineqlin: [0x1 double]
ineqnonlin: 2.2352e-007
function [c,ceq]=my(x)
c=4-x(1)^2-(x(2)-2)^2;
ceq=[];
另存为my.m
在命令窗口键入如下命令:
>> fun='(x(1)-2)^2+(x(2)-3)^2';
>> [x,fval,exitflag,output,lambda]=fmincon(fun,rand(2,1),[],[],[],[],[],[inf;2],@my)
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In fmincon at 260
Optimization terminated: first-order optimality measure less than options.TolFun
and maximum constraint violation is less than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
2
x =
2.0000
2.0000
fval =
1.0000
exitflag =
1
output =
iterations: 5
funcCount: 23
stepsize: 1
algorithm: 'medium-scale: SQP, Quasi-Newton, line-search'
firstorderopt: 3.8545e-013
cgiterations: []
message: [1x143 char]
lambda =
lower: [2x1 double]
upper: [2x1 double]
eqlin: [0x1 double]
eqnonlin: [0x1 double]
ineqlin: [0x1 double]
ineqnonlin: 2.2352e-007>> fun='(x(1)-2)^2+(x(2)-3)^2';
>> [x,fval,exitflag,output,lambda]=fmincon(fun,rand(2,1),[],[],[],[],[],[inf;2],@my)
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In fmincon at 260
Optimization terminated: first-order optimality measure less than options.TolFun
and maximum constraint violation is less than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
2
x =
2.0000
2.0000
fval =
1.0000
exitflag =
1
output =
iterations: 5
funcCount: 23
stepsize: 1
algorithm: 'medium-scale: SQP, Quasi-Newton, line-search'
firstorderopt: 3.8545e-013
cgiterations: []
message: [1x143 char]
lambda =
lower: [2x1 double]
upper: [2x1 double]
eqlin: [0x1 double]
eqnonlin: [0x1 double]
ineqlin: [0x1 double]
ineqnonlin: 2.2352e-007
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询