I want to return the value of x , description below

1 vue (au cours des 30 derniers jours)
Matthew Worker
Matthew Worker le 27 Juin 2021
Modifié(e) : Rena Berman le 16 Déc 2021
%%%%%% I want to return the x value from File 2 to File 1.
%%%% File 1
% Total Capacity After Water_filling and Genetic Algorithm
clc;
clear;
M = 60; %Number of Antennas BS
N = (6:10).^2; %Number of Elements IRS
K = 1:10; %Number of Single Antennas UE
L = 3; %Number of paths
fc = 28e9; %Carrier freq
SNR = -10; %Signal to Noise Ratio
data.Pt = 1; %Total Power
data.Pn = data.Pt/(10^(SNR/10)) ; %Noise Power
C_A = zeros(numel(N),numel(K));
Max_iter = 1;
for iter = 1:Max_iter
for n = N
%%% Millimeter wave Channel
G = M_Wave_channel_Matrix(fc, M, n, L, 'BS', 'IRS'); %NxM
data.G = G;
F = zeros(1,n);
H = zeros(1,M);
for k = K
%%% channel IRS-UE
fk = M_Wave_channel_Matrix(fc, n, 1, L, 'IRS', 'UE'); %1xN
F(K==k,:) = fk; %KxN
data.F = F;
%%% channel BS-UE
hk = M_Wave_channel_Matrix(fc, M, 1, L, 'BS', 'UE'); %1xM
H(K==k,:) = hk; %KxN
data.H = H;
%%% Genetic Algorithm
FT = @(x)-Genetic_A_Set(x,data);
A = []; % No other constraints
b = [];
Aeq = [];
beq = [];
lb = zeros(1,n);
ub = ones(1,n);
opts = optimoptions(@ga, ...
'PopulationSize', 150, ...
'MaxGenerations', 200, ...
'EliteCount', 10, ...
'FunctionTolerance', 1e-2);
[x,fval] = ga(FT,n,A,b,Aeq,beq,lb,ub,[],opts);
C_ga = -fval;
C_A(N==n,K==k) = C_A(N==n,K==k) + 1/Max_iter*(C_ga); %Algorithm Capacity
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% File 2
% Function of Genetic Algorithm
function C_ga = Genetic_A_Set(x,data)
theta = (2*pi)*(x); %Reflecting Angle IRS
Phi = diag(exp(1i*theta)); %Phase Shift Matrix for IRS. Amplitude = 1
HT = data.H+data.F*Phi*data.G; %Channel Matrix
do_waterfill = 1; % Flag
%% Rep_Water_filling
while do_waterfill
W = pinv(HT); %Precoding Matrix
W_bar = W./sqrt(sum(abs(W.^2),1));
D_Matrix = HT*W_bar; %Diagonal Matrix
D_Square = (abs(diag(D_Matrix))').^2; % Channel gains
P = waterfill(data.Pt,data.Pn./D_Square);
if any(P==0)
HT(P==0,:) = []; %Delete User Row
else
do_waterfill = 0;
end
end
R = P.*D_Square/data.Pn;
C_ga = sum(log2(1+R)); %Capacity
end
  8 commentaires
Image Analyst
Image Analyst le 15 Déc 2021
Original question
I want to return the value of x , description below
dg = sum(log2(1+R)); %Capacity
end
ok, It is completely different.
here I want to return the length of R (Length_R) from File 2, but the problem is if you read the decision below that I need to return also C_ga which I will put in FT and use for the Genetic Algorithm in file one, but Length_R I need to return it to file 1 to compare it with C_A.
Rena Berman
Rena Berman le 16 Déc 2021
(Answers Dev) Restored edit

Connectez-vous pour commenter.

Réponse acceptée

Soniya Jain
Soniya Jain le 27 Juin 2021
% Function of Genetic Algorithm
function C_ga = Genetic_A_Set(x,data)
So, instead of writing another function to find length of R, you can return the length of R in this function only,
% Function of Genetic Algorithm
function [C_ga, length_R] = Genetic_A_Set(x,data)
  9 commentaires
Soniya Jain
Soniya Jain le 28 Juin 2021
If possible, send it here only.
Matthew Worker
Matthew Worker le 29 Juin 2021
Modifié(e) : Leo Map le 29 Juin 2021
I think I should return R_length by using another function. right

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by