Optimization of matrix with constraints

2 views (last 30 days)
Zhenghao Yang
Zhenghao Yang on 30 Jul 2022
Edited: Zhenghao Yang on 31 Jul 2022
I have written a prototype function to minimize a matrix equation with code below. The input N is an even number, A and H0 are 2Nx2N matrices with real entries but complex eigenvalues.
I found the documentation of Optimization Toolbox not easy to follow, so I listed all the constraints and the equation to be minimized in the code to give my best to anyone whom would help me.
function H=extractor(N,A,H0)
A=real(A);
T0=A(1:2,1:2);
LHP = optimvar('LHP',N-1,4,'LowerBound',-2,'UpperBound',2);
RHP = optimvar('RHP',N-1,4,'LowerBound',-2,'UpperBound',2);
for q=1:N/2
if q~=N/2
UPPER(1:2,2*q-1:2*q)=[LHP(q,2),LHP(q,4);LHP(q,1),LHP(q,3)]+[RHP(N-q,2),RHP(N-q,4);RHP(N-q,1),RHP(N-q,3)];
LOWER(2*q-1:2*q,1:2)=[RHP(q,2),RHP(q,1);RHP(q,4),RHP(q,3)]+[LHP(N-q,2),LHP(N-q,1);LHP(N-q,4),LHP(N-q,3)];
elseif q==N/2
UPPER(1:2,2*q-1:2*q)=[LHP(q,2),LHP(q,4);LHP(q,1),LHP(q,3)];
LOWER(2*q-1:2*q,1:2)=[RHP(q,2),RHP(q,1);RHP(q,4),RHP(q,3)];
end
end
for q=1:N/2-1
DECAYL(q,1:4)=LHP(q,1:4)-LHP(N-q,1:4);
DECAYR(q,1:4)=RHP(q,1:4)-RHP(N-q,1:4);
end
for i=1:N
for j=1:N
d=abs(j-i);
if i<j %upper triangle
if d>N/2 % higher order
H(2*i-1:2*i,2*j-1:2*j)=[LHP(d,2),LHP(d,1);LHP(d,4),LHP(d,3)];
elseif d==N/2 % central order
H(2*i-1:2*i,2*j-1:2*j)=[LHP(d,2),LHP(d,4);LHP(d,1),LHP(d,3)];
elseif d<N/2 % lower order
H(2*i-1:2*i,2*j-1:2*j)=[LHP(d,2),LHP(d,4);LHP(d,1),LHP(d,3)];
end
elseif i>j %lower triangle
if d>N/2 % higher order
H(2*i-1:2*i,2*j-1:2*j)=[RHP(d,2),RHP(d,4);RHP(d,1),RHP(d,3)];
elseif d==N/2 % central order
H(2*i-1:2*i,2*j-1:2*j)=[RHP(d,2),RHP(d,1);RHP(d,4),RHP(d,3)];
elseif d<N/2 % lower order
H(2*i-1:2*i,2*j-1:2*j)=[RHP(d,2),RHP(d,1);RHP(d,4),RHP(d,3)];
end
elseif i==j %diagonal
H(2*i-1:2*i,2*j-1:2*j)=T0;
end
end
end
%constraint1: A(1:2,3:N+2)==UPPER && A(3:N+2,1:2)==LOWER;
%constraint2: abs(DECAYL)>0 && abs(DECAYR)>0
%minimize this equation: sum(abs(sort(real(eig(H0)))-sort(real(eig(H)))))+sum(abs(sort(imag(eig(H0)))-sort(imag(eig(H)))))

Answers (0)

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by