matlab - 使用 fmincon 进行约束最小化

标签 matlab optimization constraints

我想使用 fmincon 解决约束最小化问题.但是约束是根据 f(x_0)<a 之类的函数定义的。 , 其中x_0是解决问题的方法。可能吗?

在文档中,示例仅包含此 x_0<a形式。

代码:

f_obj = @(x)var_zcors(x,t_cw);
opt_theta = fminbnd(f_obj,0,360);

现在,x 应该被限制为 f_constraint(x)< a .

更新(来自@Phil Goddard 的回答):

f_obj = @(x)var_zcors(x,t_cw);
f_nl = @(x)deal(f_constraint(x)-a,[]);
x0 = 180; % or whatever is appropriate
opt_theta = fmincon(f_obj,x0,[],[],[],[],0,360,f_nl);

在上面的代码中说f_constraint返回一个向量 [x_min y_max]而不是标量。我想指定以下约束:

x_min>b
y_max<a

实现该目标的可能方法是什么?

最佳答案

您有一个非线性约束,因此需要使用 fmincon 的非线性约束输入。也就是说,

f_obj = @(x)var_zcors(x,t_cw);
f_nl = @(x)deal(f_constraint(x)-a,[]);
x0 = 180; % or whatever is appropriate
opt_theta = fmincon(f_obj,x0,[],[],[],[],0,360,f_nl);

如果您有多个(非线性)约束,那么根据文档中的示例,您可以编写一个函数来返回约束向量。在您的情况下,您希望在单独的 文件中编写一个函数,如下所示:

function [c,ceq] = my_nonlinear_constraints(x,ab)

% define the non-linear inequality constraints
% (This assumes that ab is a 2 element vector containing your a and b
% variables.)
[x_min,y_max] = f_constraint(x);
c = nan(2,1);
c(1) = -x_min+ab(2); % this is x_min>b
c(2) = y_max-ab(1);  % this is y_max<a

% There are no non-linear equality constraints, but this is required
ceq = [];

然后,要执行优化,您需要

% Variables a and b must be defined prior to this.
f_obj = @(x)var_zcors(x,t_cw);
f_nl = @(x)my_nonlinear_constraints(x,[a b]);
x0 = 180; % or whatever is appropriate
opt_theta = fmincon(f_obj,x0,[],[],[],[],0,360,f_nl);

关于matlab - 使用 fmincon 进行约束最小化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37754251/

相关文章:

apache-flex - 如何最小化 Flash 项目的构建时间?

matlab - MATLAB 中 ECG 信号的 FFT

arrays - 处理 Excel 的 VBA 宏中的数组

optimization - 如何识别 minizinc 问题(最大化或最小化)有多个答案

c++ - 在 C++/CLI 中从 native 转换为管理 unsigned short 的最快方法

swift - iOS - 约束和验证特征

带有 where 子句的 Oracle 唯一约束

c++ - 如何使用 c++/cplex 删除约束集的子集并向该集添加新约束?

python - Python 中 Matlab 'fscanf' 的等价物是什么?

python - matlab 的 smooth3 函数在 python 中的等价物是什么?