How can I optimize the value of a matrix?

조회 수: 17 (최근 30일)
Ahmed Nasr
Ahmed Nasr 2020년 3월 28일
댓글: Ahmed Nasr 2020년 4월 1일
I want to find the optimal B matrix (2*4 matrix) that makes the elements of beta_d (1*4 vector) which is a function of B matrix, equal to the corresponding ones of a "given" beta_u (1*4 vector), i.e. I want to obtain the value of B matrix that makes beta_d(1,1) = beta_u(1,1) && beta_d(1,2) = beta_u(1,2) && beta_d(1,3) = beta_u(1,3) && beta_d(1,4) = beta_u(1,4).
On my attached code, as I am a beginner in MATLAB, I generated random value of B matrix and used 'while loop' to check if my condition is satisfied or not. This way is not efficient and takes very long time to give me a result.
Can anyone help me to optimize the value of B matrix in more efficient and faster way?
% Given H (4*2 matrix)
% Given A (2*2 diagonal matrix)
% Given C (4*4 matrix)
% Given P (4*4 diagonal matrix)
% Given C_l = 4; (constant value)
% Given beta_u (1*4 vector)
% I want to find the optimal B matrix (2*4 matrix) that makes the elements of the 1*4 beta_d vector equal to the corresponding ones of beta_u 1*4 vector
% i.e I want beta_d(1,1) = beta_u(1,1) && beta_d(1,2) = beta_u(1,2) && beta_d(1,3) = beta_u(1,3) && beta_d(1,4) = beta_u(1,4)
%% My non-efficient code:
B = zeros(2,4); % intial value of B 2*4 matrix
beta_d = zeros(1,4); %intial value of beta_d 1*4 vector
% compare each element of beta_d with the corresponding one in beta_u
% optimize the value of B
while(beta_d(1) ~= beta_u(1) || beta_d(2) ~= beta_u(2) || beta_d(3) ~= beta_u(3) || beta_d(4) ~= beta_u(4)) %check the condition
B = randn(2,4); % generate a random 2*4 B matrix
for j=1:1:2 % calculcate the 2*2 diagonal D matrix whose value depends on B
d(j) = (B(j,:)*P*B(j,:)')/((2^(2*C_l))-(norm(A(:,j))^2));
end
D = diag(d);
for i=1:1:4 % calculate beta_d (1*4 vector) whose value depends on B and D
V_d(i)=C(i,:)*P*B'*H(i,:)'*inv(1+H(i,:)*(A'*D*A+B*P*B')*H(i,:)');
sigma_d(i)=norm((V_d(i)*H(i,:)*B-C(i,:))*(P^(1/2)))^2+(V_d(i)^2)*(1+H(i,:)*A'*D*A*H(i,:)');
beta_d(i)=((P(i,i))/sigma_d(:,i));
end
end
  댓글 수: 2
Alexandra McClernon Ownbey
Alexandra McClernon Ownbey 2020년 3월 28일
you should initialize everything that is inside a for loop which means your variable will initialize for each iteration of the while loop. It also looks like you are checking your guess against a known value of integers. This also takes a long time since you don't give it a tolerance.
Ahmed Nasr
Ahmed Nasr 2020년 3월 29일
I set a tolerance and it takes a very long time too!
How can I use non-linear optimization to solve my problem?

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2020년 3월 29일
편집: Rik 2020년 3월 30일
The code below will fit a value for B with the fminsearch function. Note that it is relatively sensitive to a good initial guess. There are still several warnings mlint is giving you, but I will leave those for you to resolve.
edit: added the actual definitions for the input parameters
H = [-0.3208 -0.9784; -1.5994 -1.4689; -1.5197 -0.4568; -0.0993 -0.7667]; % 4*2 matrix
A = [-1 1; 0 1]; % 2*2 matrix
C = [-0.20 0.4 0.6 -0.2; -0.2 0.4 0.6 -0.2; 0.4 0.2 -0.2 0.4; 0.4 0.2 -0.2 0.4]; % 4*4 matrix
P = [250000 0 0 0; 0 250000 0 0; 0 0 250000 0; 0 0 0 250000]; % 4*4 matrix
C_l = 4; % constant value
beta_u = [50.2207 50.2207 20.3433 20.3433]; % 1*4 vector
%store inputs to a struct for shorter syntax
s=struct;[s.H,s.A,s.C,s.P,s.C_l]=deal(H,A,C,P,C_l);
initial_guess=randn(2,4);
OLS=@(b,input_vars)sum((myfun(b,input_vars) - beta_u).^2);%ordinary least squares cost function
opts = optimset('MaxFunEvals',50000, 'MaxIter',10000);
fit_val = fminsearch(OLS, initial_guess, opts,s);
function beta_d=myfun(B,input_vars)
%calculate beta_d from B and the other inputs
%load parameters
s=input_vars;[H,A,C,P,C_l]=deal(s.H,s.A,s.C,s.P,s.C_l);
beta_d = zeros(1,4); %intial value of beta_d 1*4 vector
for j=1:1:2 % calculcate the 2*2 diagonal D matrix whose value depends on B
d(j) = (B(j,:)*P*B(j,:)')/((2^(2*C_l))-(norm(A(:,j))^2));
end
D = diag(d);
for i=1:1:4 % calculate beta_d (1*4 vector) whose value depends on B and D
V_d(i)=C(i,:)*P*B'*H(i,:)'*inv(1+H(i,:)*(A'*D*A+B*P*B')*H(i,:)');
sigma_d(i)=norm((V_d(i)*H(i,:)*B-C(i,:))*(P^(1/2)))^2+(V_d(i)^2)*(1+H(i,:)*A'*D*A*H(i,:)');
beta_d(i)=((P(i,i))/sigma_d(:,i));
end
end
  댓글 수: 15
Ahmed Nasr
Ahmed Nasr 2020년 3월 30일
Yes, thank you for your efforts. I really apperiate it.
Ahmed Nasr
Ahmed Nasr 2020년 4월 1일
If I can ask you another question:
I have 4 users, and I want to simulate the outage probability which is the probability of the user data rate is less than the predefined threshold value i.e. if the threshold rate per user is = 0.512.
After changing the signal to noise ratio SNR from -20 dB to 30 dB, I obtain the rate matrix with dimensions (number of users × the length of SNR vector), where each element in this matrix represents the rate of certain user at specific SNR value as follows:
SNR_vector_dB=-20:10:30; %the SNR vector
R_th = 0.512; % the user data rate threshold value
% Rate matrix with dimensions (number of users =4 * the length of SNR vector=6)
R = [0.0021 0.0191 0.1466 0.7368 1.5617 1.9838; ...
0.0021 0.0191 0.1466 0.7368 1.5617 1.9838; ...
0.0041 0.0370 0.3190 0.9267 1.6591 2.1856; ...
0.0041 0.0370 0.3190 0.9267 1.6591 2.1856];
Can you help me in simulating the outage probability versus SNR?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by