I want to return the value of x , description below

조회 수: 1 (최근 30일)
Matthew Worker
Matthew Worker 2021년 6월 27일
편집: Rena Berman 2021년 12월 16일
%%%%%% 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
Image Analyst
Image Analyst 2021년 12월 15일
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 2021년 12월 16일
(Answers Dev) Restored edit

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

채택된 답변

Soniya Jain
Soniya Jain 2021년 6월 27일
% 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
Soniya Jain
Soniya Jain 2021년 6월 28일
If possible, send it here only.
Matthew Worker
Matthew Worker 2021년 6월 29일
편집: Leo Map 2021년 6월 29일
I think I should return R_length by using another function. right

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by