如何使用Octave/MATLAB的通用优化程序

How use the generic optimization program of Octave / MATLAB

不好意思打扰了,我正在和Octave的说明书打架,没有任何结果。

我想在一些约束条件下最大化一个有点复杂的函数:

这个函数在数学上与这个相似(我写这个是为了简化解释):

f(x, y, z, t) = arcsin (x/2t)/(y + x + max (1, z/t))

z,t 在 0 和 1 之间,x 在 1 和 2 之间,y 大于 1/x^2。

你能给我代码来计算 x、y、z 和 t 的数值以使这个函数最大化吗?从这段代码中,我将推导出优化函数应该如何使用。

对我有很大帮助。

非常感谢

您可以使用 fminconfmincon and minimize the additive inverse of your objective function. your constraint ("y greater than 1/x^2") is nonlinear so you should use the nonlcon 参数:

% function definition (minus sign to maximize instead of minimize)
f = @(x) - asin(x(1)/(2*x(4)))/(x(2) + x(1) + max(1, x(3)/x(4)) );
lb = [1 -inf 0 0];% lower bound for [x y z t]
ub = [2 inf 1 1];% upper bound for [x y z t]
x0 = [1.5 0 0.5 0.9]; % initial vector
% minimization
x = fmincon(f,x0,[],[],[],[],lb,ub,@mycon);

其中 mycon 定义了您的约束条件:

function [c,ceq] = mycon(x)
% y > 1/x^2
% 1/x^2 - y < 0
c = 1/x(1)^2 - x(2);
ceq = 0;
end

您还可以传递一个 options 参数来指定优化选项。