Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
396 views
in Technique[技术] by (71.8m points)

matlab - 使用fmincon()求解矩阵形式的特殊非线性程序(Solving a special nonlinear program in matrix form using fmincon())

My problem is the following optimization problem:

(我的问题是以下优化问题:)

min J=X'*E*X+U'*E*U
s.t. X'- X0'-(X')*D1*Q*P+(X')*D1*Q*Z=0,
     I*I'*(D2')*U-Q*I=0

where X and U are 2*r+1 by 1 column matrices, X0 is 2*r+1 by 1 known column matrix and E, D1, D2, P and Z are known 2*r+1 by 2*r+1 matrices and I is a 2*r+1 by 1 known column matrix.

(其中XU2*r+1 by 1列矩阵, X02*r+1 by 1已知列矩阵,而E, D1, D2, P and Z已知2*r+1 by 2*r+1矩阵和I2*r+1 by 1已知列矩阵。)

Also, Q is a matrix which satisfied in I*I'*(D2')*U=Q*I .

(而且,Q是满足I*I'*(D2')*U=Q*I的矩阵。)

Known matrices: X0, E, D1, D2, Z, P, I

(已知矩阵: X0, E, D1, D2, Z, P, I)

Thanks in advance.

(提前致谢。)

My try: (我的尝试:)

Ojective function file name: objective_function.m

(射影函数文件名: objective_function.m)

function objective = objective_function(input,r, E)

X = input(1:2*r+1);
U = input(2*r+2:end);
objective = (X')*E*X +(U')*E*U;
end

Constraint function file name: constraint.m

(约束函数文件名: constraint.m)

function [inequality, equality] = constraint(input, r,  X0, Z, I, P, Q, D1, D2)
X = input(1:2*r+1);
U = input(2*r+2::end);
% No inequality constraint 
inequality = [];
equality = [X'- X0'-(X')*D1*Q*P+(X')*D1*Q*Z ; I*I'*(D2')*U-Q*I];
end

Optimization file name: main.m

(优化文件名: main.m)

   clear all
    clc
    r=2;

    % X0
      X0(1)=1;
    for i=2:2*r+1
        X0(i)=0;
    end
    X0=X0';
    % P
    P1=[1/2];
    P2=zeros(1,r);
    for i=1:r
        P3(i)=(-1)/(i*pi);
    end
    P4=zeros(r,1);
    P5=zeros(r,r);
    for i=1:r
        V1(i)=1/(2*i*pi);
    end
    P6=diag(V1);
    for i=1:r
        W(i)=1/(2*i*pi);
    end
    P7=W';
    for i=1:r
        V2(i)=(-1)/(2*i*pi);
    end
    P8=diag(V2);
    P9=zeros(r,r);
    P=3*[P1 P2 P3 ; P4 P5 P6 ; P7 P8 P9];
    % D1
    M1=[1];
    M2=zeros(1,r);
    M3=zeros(1,r);
    M4=zeros(r,1);
    for i=1:r
        V4(i)=cos((2*i*pi)/3);
    end
    M5=diag(V4);
    for i=1:r
        V5(i)=sin((2*i*pi)/3);
    end
    M6=diag(V5);
    M7=zeros(r,1);
    for i=1:r
        V6(i)=-sin((2*i*pi)/3);
    end
    M8=diag(V6);
    for i=1:r
        V7(i)=cos((2*i*pi)/3);
    end
    M9=diag(V7);
    D1=[M1 M2 M3 ; M4 M5 M6 ; M7 M8 M9];

    % D2
    N1=[1];
    N2=zeros(1,r);
    N3=zeros(1,r);
    N4=zeros(r,1);
    for i=1:r
        VV4(i)=cos((2*i*pi*2)/3);
    end
    N5=diag(VV4);
    for i=1:r
        VV5(i)=sin((2*i*pi*2)/3);
    end
    N6=diag(VV5);
    N7=zeros(r,1);
    for i=1:r
        VV6(i)=-sin((2*i*pi*2)/3);
    end
    N8=diag(VV6);
    for i=1:r
        VV7(i)=cos((2*i*pi*2)/3);
    end
    N9=diag(VV7);
    D2=[N1 N2 N3 ; N4 N5 N6 ; N7 N8 N9];

    % Z
    Z1=[1];
    Z2=zeros(1,2*r);
    for i=1:r
        Z3(i)=(3/(2*i*pi))*sin((2*i*pi)/3);
    end
    Z3=Z3';
    Z4=zeros(r,2*r);
    for i=1:r
        Z5(i)=(3/(2*i*pi))*(1-cos((2*i*pi)/3));
    end
    Z5=Z5';
    Z6=zeros(r,2*r);
    Z=[Z1 Z2 ; Z3 Z4 ;Z5 Z6];

     % E
    V3(1)=2;
    for i=2:2*r+1
        V3(i)=1;
    end
    E=diag(V3);

    % PHi
     R1=@(x) arrayfun(@(i)cos(i*pi*x),1:r);
     R2=@(x) arrayfun(@(i)sin(i*pi*x),1:r);
     R = @(t) [1, R1(t), R2(t)];
     I=R(1);
     I=I';


     A=[];
    b=[];
    Aeq=[];
    beq=[];
    lb=[];
    ub=[];

       initial=ones(4*r+2,1);
   %% All function should have a unique vector as input
% Objective function
J =@(decision_variable)objective_function(decision_variable, r, E);

% Constraint
equality = @(decision_variable)constraint(decision_variable, r, X0, Z, I, P, Q, D1, D2);



solution = fmincon(J,initial,A,b,Aeq,beq,lb,ub,equality);

% X and U extraction 
 X_sol = solution(1:2*r+1);
 U_sol = solution(2*r + 2:end);





  ask by M.Ramana translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...