免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3131 | 回复: 0
打印 上一主题 下一主题

[备忘录] MATLAB优化工具箱搭建数学模型 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-02-23 16:36 |只看该作者 |倒序浏览
   
Myblog
Email:
bananan.0420@yahoo.com.cn
   
     回校后工作的第一天,顺利! 2009年2月23日
     哈哈哈,这次模型搭建是我完成的最快的一次啦!
     上午讨论完,将模型实现步骤推敲的差不多,下午用了3小时左右时间和组员,熟悉MATLAB Optimization Toolbox (GA),编写自己的Fitness function, 并且把我们的限制条件(非线性等式)加入到工具箱中,并且运行了简单的数据,好开心,没想到这么快就完成啦!


    以下是个简单的备忘录:
1. Fitness function的书写主要是自己建模的内容,加入到工具箱中的步骤并不难!

2. Constraints 的添加的确费了好些时间
   优化问题的限制条件一般是对独立变量的取值范围进行限制,而变量间的关系则是独立的,互不影响;
   我们的模型,变量间需要满足一个非线性等式,所以进行设置时费了一些时间才弄明白具体的实现,为此,我总结一下限制条件设置的操作,方便以后使用时进行查阅和参考!
   最后的解决方法思路,是在MATLAB官网上找得到的,发现解决问题还真得找正宗的啊!

   如何向Optimization ToolBox中的(优化/目标)函数的参数传递额外的限制条件
   How do I pass additional parameters to the constraint and objective functions in the Optimization Toolbox functions?

   
Subject:
How do I pass additional parameters to the constraint and objective functions in the Optimization Toolbox functions?
Problem Description:
I would like to parameterize my objective function and constraint function in my optimization problem using the Optimization toolbox. Typically this is needed when I want to use parameters and design variables together in an optimization problem.
Solution:
You can pass additional parameters to the nonlinear constraint function as well as objective function using anonymous functions, inline functions, or function files for the objective and constraint functions. An example of this is given below.
Anonymous functions allow you to parameterize your objective and constraint functions.
The objective function "fun" can be defined in a function file:
function f = fun(x,p1)
f = -x(1) * x(2) * x(3)*p1;
(非线性限制条件)
The nonlinear constraint function "nonlcon" is :
function [c, ceq] = nonlcon(x,p1,p2)
(非线性不等式限制条件)
% Define two inequality constraints which use parameters P1 and P2
c(1) = x(1)*p1 + 2*x(2)*x(1)*p2 + 2*x(3) - p2;
c(2) = x(1)*x(2)-100;
(非线性等式限制条件)
% Define the equality constraints
ceq(1) = x(2) -x(1)*x(2);
ceq(2) = x(2) - x(1)*x(3);
The call to FMINCON where the additional parameter P1 is passed to the objective function, and parameters P1 and P2 to the constraint function is:
x0 = [10; 10; 10];
p1 = 1;
p2 = 72;
lb = [0 0 0];
ub = [ 50 50 50];
options = optimset('Largescale','off','Display','iter');
[x, fval] = fmincon(@(x)fun(x,p1), x0, [], [], [], [], lb, ub, @(x)nonlcon(x,p1,p2), options)
For simple objective functions, it is possible to define the objective function in the call to FMINCON, and have no objective function file:
[x, fval] = fmincon(@(x)-x(1)*x(2)*x(3)*p1, x0, [], [], [], [], lb, ub, @(x)nonlcon(x,p1,p2), options)
The ODE functions use the same convention for handling additional parameters as is described here. Additional information about the ODE solvers can be found in the related solution below.
MATLAB官网上的出处

Myblog
Email:
bananan.0420@yahoo.com.cn



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/105477/showart_2185240.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP