为fmincon分离实部和虚部的问题(约束MATLAB优化)。如何正确编程?

时间:2019-05-20 13:43:25

标签: matlab complex-numbers nonlinear-optimization

我正在尝试使用 MATLAB 中的 fmincon 功能解决此优化问题:

enter image description here

所有H是复矩阵,g和Pdes是复列向量,D0和E0是数字。

我希望得到g的复杂列向量(并且一般来说应该是复杂的),所以我将问题分为两部分:实数部分和imag,但是它不起作用,MATLAB向我返回一条消息:

Not enough input arguments.

Error in temp>nonlincon (line 17)
c(1) = norm ( H_d*([g(1)+1i*g(4); g(2)+1i*g(5); g(3)+1i*g(6)]) )^2 - D_0;

Error in temp (line 12)
        = fmincon(objective,x0,[],[],[],[],[],[],nonlincon);

我哪里错了?

总的来说,我可以通过以下方式写出给定的问题吗??

% For example:
D_0 = 2*10^(-5)*10^(60/10);
E_0 = 50;
H_b = rand(15,3) + 1i*rand(15,3);
P_des = rand(15,1) + 1i*rand(15,1);
H_d = rand(10,3) + 1i*rand(10,3);

    objective = @(g) (norm ( H_b*([g(1)+1i*g(4); g(2)+1i*g(5); g(3)+1i*g(6)]) - P_des ))^2;                        
x0 = ones(1,3*2)';
options = optimoptions('fmincon','MaxFunctionEvaluations',10e3);
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN]...
        = fmincon(objective,x0,[],[],[],[],[],[],nonlincon);

% So I expect to get a column vector g: 1st 3 elements - Real part, next 3 - Imag

function [c,ceq] = nonlincon(g, H_d, E_0, D_0)
c(1) = (norm ( H_d*([g(1)+1i*g(4); g(2)+1i*g(5); g(3)+1i*g(6)]) ))^2 - D_0;                        
c(2) = (norm ([g(1)+1i*g(4); g(2)+1i*g(5); g(3)+1i*g(6)]))^2 - E_0;
ceq = [];
end

1 个答案:

答案 0 :(得分:0)

仅在调用nonlincon时才需要指定fmincon是变量g的函数

代码如下

[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN]...
        = fmincon(objective,x0,[],[],[],[],[],[],@(g)nonlincon(g, H_d, E_0, D_0));

解决方案X

X = [0.2982; 0.1427; 0.3597; -0.0729; -0.1187; 0.2090]