数学建模 非线性规划

在这里插入图片描述
一个很好的例子,列出优化模型和里面的约束条件
在这里插入图片描述

求解:
在这里插入图片描述

示例
在这里插入图片描述
求解结果

(x取(1,1)时获得最小值10)

>> main

Local minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the default value of the optimality tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.

<stopping criteria details>


x =

    1.0000
    1.0000


y =

   10.0000
% 主函数
options=optimset;
[x,y]=fmincon('func1',rand(2,1),[],[],[],[],zeros(2,1),[],'func2',options)
%目标函数
function f=func1(x);
f=x(1).^2+x(2).^2+8;
%非线性向量函数(非线性约束)
function [g,h]=func2(x);
g=-x(1).^2+x(2);
h=-x(1)-x(2).^2+2;

在这里插入图片描述
求解结果

>> main

Local minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the default value of the optimality tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.

<stopping criteria details>


x =

   86.1884
  104.2878
  126.1883
  152.6878


y =

  -43.0860

代码

% 主函数
options=optimset;
a=[1.1 1 0 0;1.21 1.1 1 0;1.331 1.21 1.1  1];
b=[440;484;532.4];
ub=[400;inf;inf;inf];
[x,y]=fmincon('func1',rand(4,1),a,b,[],[],zeros(4,1),ub,[],options)
function f=func1(x);
f=-(sqrt(x(1))+sqrt(x(2))+sqrt(x(3))+sqrt(x(4)));

还可以把约束条件都写到一个函数里,结果一样

% 主函数
[x,y]=fmincon('func1',rand(4,1),[],[],[],[],zeros(4,1),[],'func2',optimset)
%非线性向量函数(非线性约束)
function [g,ceq]=func2(x);
g(1)=x(1)-400;
g(2)=1.1*x(1)+x(2)-440;
g(3)=1.21*x(1)+1.1*x(2)+x(3)-484;
g(4)=1.331*x(1)+1.21*x(2)+1.1*x(3)+x(4)-532.4;
ceq=0;
function f=func1(x);
f=-(sqrt(x(1))+sqrt(x(2))+sqrt(x(3))+sqrt(x(4)));
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值