# how to find the optimal value of a matrix that minimize a function?

35 views (last 30 days)
Adi Nor on 3 Mar 2020
Commented: Adi Nor on 5 Mar 2020
I have a matrix W which is a block diagonal matrix with dimensions , and each of its two block diagonal is vector. I want to find the values of its enteries that minimze the difference between the following function: Where: W is the required block diagonal matrix to be optimized, B is a matrix, H is a given matrix, and A is a matrix. A and B are calculated using the functions used in the attached code.
It tried this attached code, but I think it is now in infinte loop and I don't know what should I do?
while ((B*H)-(A*W)~=zeros(2,4))
w1=randn(1,2); % generate the first block diagonal vector with dimensions 1*2. The values of each entry of the block
% diagonal vector may be not the same.
w2=randn(1,2); % generate the second block diagonal vector with dimensions 1*2.
W=blkdiag(w1,w2); % bulid the block diagonal matrix that I want to optimize with dimmensions 2*4.
R=sqrtm(W*inv(inv(P)+(H'*inv(eye(2)+D)*H))*W'); % R is 2*2 matrix that will be used to calculate matrix A using LLL lattice
% reduction algorithm. The values of P (4*4 matrix), H (2*4 matrix) and D (2*2 matrix) are given. It's clear here that
% matrix R is a function of W.
A= LLL(R,3/4); % I use here LLL lattice reduction algorithm to obtain 2*2 matrix A which is function of R.
B=A'*W*P*H'*inv(eye(2)+D+H*P*H'); % B is 2*2 matrix which is function of A and W. The values of P (4*4 matrix),
% H (2*4 matrix) and D (2*2 matrix) are given.
end

Stephen Cobeldick on 3 Mar 2020
Do you have the Optimization Toolbox or Global Optimization Toolbox?
Adi Nor on 3 Mar 2020
Yes, but I don't know how to use them. So, I tried to optmize the matrix using the attached code.

Fabio Freschi on 3 Mar 2020
If I understand correctly the problem can be recast to the following
A*W = B*H = F;
[a11 a12; a21 a22]*[w1 w2 0 0; 0 0 w3 w4] = [f11 f12 f13 f14; f21 f22 f23 f24];
If so, it is possible to write it in terms of another linear system
A0*w0 = f0;
[A 0 0 0; 0 A 0 0; 0 0 A 0; 0 0 0 A]*[w1 0 w2 0 0 w3 0 w4]' = [f11 f21 f12 f22 f13 f23 f14 f24];
Where A0 is 8x8, w0 is 8x1 and f is 8x1.
This is actually a over determined system, because some of the unknowns (at positions 2 4 5 and 7) are actually zeros, so we can delete the corresponding cols of A0, having a 8x4 matrix. This can be solved with backslash, which gives the linear least squares solution. I don't have the actual matrices, so I play with dummy values
% this is your matrix A
A = eye(2)+rand(2);
% this is the result of the product of your matrices B*H
F = rand(2,4);
% create the 8x8 system
A0 = blkdiag(A,A,A,A);
% create the rhs
f = F(:);
% remove the 2 4 5 7 cols from A0
A0(:,[2 4 5 7]) = [];
% now get the least squares solution
w = A0\f
% result with your notation w1 and w2
w1 = [W(1) W(2)];
w2 = [W(3) W(4)];
hope it helps

Adi Nor on 5 Mar 2020
Thank You. It works well now with me.
I have another question related to the same problem. Using the same method in your answer, How can I find the optimal entries of W that minimze the function F? Where:
F = sqrtm(W*A*W'), F is a 2*2 matrix is the function to be minimized.
A is a "given" 4*4 matrix not random.
W is 2*4 block diagonal matrix in which each block diagonal is 1*2 vector. W' is the transpose of matrix W that we want to minimize.
Fabio Freschi on 5 Mar 2020
what do you mean with "minimize a matrix", given that F is a 2x2 matrix?
Adi Nor on 5 Mar 2020
F is 2*2 matrix and equal to F = sqrtm(W*A*W'), where W and A are also matrices. A is 4*4 full rank matrix given with me. I don't to know the values of matrix F and W. So, I want to find the optimal entries of matrix W that minimize for example the L-2 norm of F. Subject to:
F = sqrtm(W*A*W'), F is a 2*2 matrix is the function to be minimized.
A is a "given" 4*4 matrix not random.
W is 2*4 block diagonal matrix in which each block diagonal is 1*2 vector. W' is the transpose of matrix W that we want to minimize.
The l-2 norm value of W and A must be greater than zero.