使用fminsearch最大化功能 [英] Maximize function with fminsearch

查看:178
本文介绍了使用fminsearch最大化功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的日常工作中,我必须最大限度地利用 fminsearch ;代码是:

  clc 
清除所有
关闭所有

f = (x(2)/ c)^ 3 *(((exp( - (x(1)/ c)^ k)-exp( - (x(2)/ c) K))/((X(2)/ C)^ K-(X(1)/ C)^ k))的 - EXP( - (X(3)/ C)^ k))的^ 2;
c = 10.1;
k = 2.3;
X = fminsearch(@(x)f(x,c,k),[4,10,20]);

按我的预计,它工作正常,但不是问题即将出现:我需要绑定x在一定范围内,如下所示:

  4 < x(1)< 5 
10< x(2) 15
20< ×(3) 30

为了获得正确的结果,我应该使用优化工具箱,但我不能接受。 / p>

有什么办法可以通过仅使用fminsearch来获得相同的分析结果吗?

解决方案好吧,不直接使用fminsearch,但如果你愿意下载 fminsearchbnd 从文件交换,然后是的。 fminsearchbnd 对一般目标函数进行约束约束最小化,作为覆盖在fminsearch上。它为你调用fminsearch,应用这个问题的界限。

基本上,这个想法是为你改变你的问题,使你的目标函数看起来好像它正在解决一个约束问题。它是完全透明的。您可以使用函数(参数空间的起点)调用 fminsearchbnd ,和一组下限和上限。



例如,最小化rosenbrock函数会返回fminsearch的[1,1]处的最小值。但是,如果我们对每个变量的问题2应用纯粹的下界,那么fminsearchbnd在[2,4]处找到约束约束解。

 <$ (x)(1-x(1))。^ 2 + 105 *(x(2)-x(1)。^ 2)。^ 2; 

fminsearch(rosen,[3 3])%unconstrained
ans =
1.0000 1.0000

fminsearchbnd(rosen,[3 3],[2 2],[])%受限制
ans =
2.0000 4.0000

如果你对变量没有约束,然后提供-inf或inf作为相应的边界。

  fminsearchbnd(rosen,[3 3 ],[ -  inf 2],[])
ans =
1.4137 2


Within my daily work, I have got to maximize a particular function making use of fminsearch; the code is:

clc
 clear all
 close all

 f = @(x,c,k) -(x(2)/c)^3*(((exp(-(x(1)/c)^k)-exp(-(x(2)/c)^k))/((x(2)/c)^k-(x(1)/c)^k))-exp(-(x(3)/c)^k))^2;
 c = 10.1;
 k = 2.3;
 X = fminsearch(@(x) f(x,c,k),[4,10,20]);

It works fine, as I expect, but not the issue is coming up: I need to bound x within certain limits, as:

 4 < x(1) < 5
 10 < x(2) < 15
20 < x(3) < 30

To achieve the proper results, I should use the optimization toolbox, that I unfortunately cannot hand.

Is there any way to get the same analysis by making use of only fminsearch?

解决方案

Well, not using fminsearch directly, but if you are willing to download fminsearchbnd from the file exchange, then yes. fminsearchbnd does a bound constrained minimization of a general objective function, as an overlay on fminsearch. It calls fminsearch for you, applying bounds to the problem.

Essentially the idea is to transform your problem for you, in a way that your objective function sees as if it is solving a constrained problem. It is totally transparent. You call fminsearchbnd with a function, a starting point in the parameter space, and a set of lower and upper bounds.

For example, minimizing the rosenbrock function returns a minimum at [1,1] by fminsearch. But if we apply purely lower bounds on the problem of 2 for each variable, then fminsearchbnd finds the bound constrained solution at [2,4].

rosen = @(x) (1-x(1)).^2 + 105*(x(2)-x(1).^2).^2;

fminsearch(rosen,[3 3])     % unconstrained
ans =
   1.0000    1.0000

fminsearchbnd(rosen,[3 3],[2 2],[])     % constrained
ans =
   2.0000    4.0000

If you have no constraints on a variable, then supply -inf or inf as the corresponding bound.

fminsearchbnd(rosen,[3 3],[-inf 2],[])
ans =
       1.4137            2

这篇关于使用fminsearch最大化功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆