Find the optimal value to maximize a function

Hi everyone.....could anyone help......I need to find th optimal value of x0 and x1 to maximize R, where x1=d-x0..........the function MATLAB code:
close all; clear all; clc;
% System parameters
F = 10000; % Number of files
S = 100; % SBS cache capacity (set to 100)
M = 50; % Cash capacity fraction
alpha = 2; % Path loss exponent for LOS link
c = 3e8; % Light speed
fr = 1e12; % Operating frequency
B = 10e6; % System bandwidth
epsilon = 0.8; % Skewness factor
K = 0.0016; % Molecular absorption coefficient
P_M = 10^(64/10); % Transmit power MBS
P_S = 10^(30/10); % Transmit power SBS
sigma = 10^(-90/10); % Noise power
N_L = 512;
N_M = 16;
eta = 1;
x2 =30; % RIS-MBS distance
d_range = 1:1:40;
R = zeros(size(d_range));
for i = 1:length(d_range)
d = d_range(i);
sum1 = 0;
for f = 1:F
sum1 = sum1 + f^(-epsilon);
end
sum2 = 0;
for f = 1:M
sum2 = sum2 + f^(-epsilon)/sum1;
end
sum3 = 0;
for f = (M + 1):(M + (S - M) / eta)
sum3 = sum3 + (f^(-epsilon)) / sum1;
end
sum3 = sum3 * eta;
beta = (c/(4*pi*fr))^2; % Spreading loss index
Rs = B * log2(1 + (P_S * beta * (d-x1)^(-alpha) * exp(-K * (d-x1))) / sigma);
Rm = B * log2(1 + (P_M * (N_L^2) * N_M * (beta * (d-x0)^(-alpha) * exp(-K * (d-x0))) * (beta * x2^(-alpha) * exp(-K * x2))) / sigma);
Rt = Rs * (sum2 + sum3) + Rm * (1 - (sum2 + sum3));
R(i) = Rt;
end
figure
plot(d_range, R, 'b^-')
xlabel('SBS-RIS Distance, d')
ylabel('Achievable Rate')

 采纳的回答

Hi
seems to me that R curves goes up as x0 goes closer to zero (but not rqual to zero otherwise you get Inf values)
also all the small for loops to create the sum1, sum2,sum3 variables can be replaced with sum function directly
close all; clear all; clc;
x0_range = [0.01 0.25 0.5 1];
% System parameters
F = 10000; % Number of files
S = 100; % SBS cache capacity (set to 100)
M = 50; % Cash capacity fraction
alpha = 2; % Path loss exponent for LOS link
c = 3e8; % Light speed
fr = 1e12; % Operating frequency
B = 10e6; % System bandwidth
epsilon = 0.8; % Skewness factor
K = 0.0016; % Molecular absorption coefficient
P_M = 10^(64/10); % Transmit power MBS
P_S = 10^(30/10); % Transmit power SBS
sigma = 10^(-90/10); % Noise power
N_L = 512;
N_M = 16;
eta = 1;
x2 =30; % RIS-MBS distance
d_range = 1:1:40;
R = zeros(numel(d_range),numel(x0_range));
for k = 1:numel(x0_range)
x0 = x0_range(k);
for i = 1:length(d_range)
d = d_range(i);
x1 = d-x0; % added line
% sum1 = 0;
% for f = 1:F
% sum1 = sum1 + f^(-epsilon);
% end
f = 1:F;
sum1 = sum(f.^(-epsilon));
% sum2 = 0;
% for f = 1:M
% sum2 = sum2 + f^(-epsilon)/sum1;
% end
f = 1:M;
sum2 = sum(f.^(-epsilon))/sum1;
% sum3 = 0;
% for f = (M + 1):(M + (S - M) / eta)
% sum3 = sum3 + (f^(-epsilon)) / sum1;
% end
% sum3 = sum3 * eta;
f = (M + 1):(M + (S - M) / eta);
sum3 = eta*sum(f.^(-epsilon))/sum1;
beta = (c/(4*pi*fr))^2; % Spreading loss index
Rs = B * log2(1 + (P_S * beta * (d-x1)^(-alpha) * exp(-K * (d-x1))) / sigma);
Rm = B * log2(1 + (P_M * (N_L^2) * N_M * (beta * (d-x0)^(-alpha) * exp(-K * (d-x0))) * (beta * x2^(-alpha) * exp(-K * x2))) / sigma);
Rt = Rs * (sum2 + sum3) + Rm * (1 - (sum2 + sum3));
R(i,k) = Rt;
leg{k} = ['x0 = ' num2str(x0)];
end
end
plot(d_range, R, '^-')
legend(leg)
xlabel('SBS-RIS Distance, d')
ylabel('Achievable Rate')

8 个评论

Thanks a lot @Mathieu NOE......do you think that I should use x0_range instead of d_range?.....Also how can I use the exaustive search to find the optimal value?
I am not sure to understand fully your problem... how many independant parameters do we have ?
only d and x0 ?
what is the range for each one ?
can you confirm that x1=d-x0 so x1 is not an independant parameter (I added this in the corrected code)
then why are you still using x1 in this line :
Rs = B * log2(1 + (P_S * beta * (d-x1)^(-alpha) * exp(-K * (d-x1))) / sigma);
Sorry for the confussion @Mathieu NOE...Let me elaborate more here:
So, I have a fixed distant (d=40) between the RIS (reflector) and the SBS station and I have a user between the RIS and the SBS. The distance between the RIS and the user is x1, and the distance between the user and the SBS is x0. We have (x0 + x1 = d), so I need to find the optimal value of x0 that maximize the rate R..........
Then, if we find the optimal value of x0, x1 will be found already as we have (x1=d-x0).
This is what I get now
still I wonder what x2 is doing here
x2 =30; % RIS-MBS distance (what is MBS ? )
as x2 is used in the Rm computaion
Rm = B * log2(1 + (P_M * (N_L^2) * N_M * (beta * (d-x0)^(-alpha) * exp(-K * (d-x0))) * (beta * x2^(-alpha) * exp(-K * x2))) / sigma);
is x2 fix or dependant of x0 ?
so far the new code is showing that maximum rate is obtained if the user is close either to the RIS or the SBS
% System parameters
F = 10000; % Number of files
S = 100; % SBS cache capacity (set to 100)
M = 50; % Cash capacity fraction
alpha = 2; % Path loss exponent for LOS link
c = 3e8; % Light speed
fr = 1e12; % Operating frequency
B = 10e6; % System bandwidth
epsilon = 0.8; % Skewness factor
K = 0.0016; % Molecular absorption coefficient
P_M = 10^(64/10); % Transmit power MBS
P_S = 10^(30/10); % Transmit power SBS
sigma = 10^(-90/10); % Noise power
N_L = 512;
N_M = 16;
eta = 1;
x2 =30; % RIS-MBS distance
d = 40;
x0_range = linspace(0.01*d,0.99*d,100);
R = zeros(1,numel(x0_range));
for k = 1:numel(x0_range)
x0 = x0_range(k);
x1 = d-x0; % added line
%sum1 computation
f = 1:F;
sum1 = sum(f.^(-epsilon));
%sum2 computation
f = 1:M;
sum2 = sum(f.^(-epsilon))/sum1;
%sum computation
f = (M + 1):(M + (S - M) / eta);
sum3 = eta*sum(f.^(-epsilon))/sum1;
beta = (c/(4*pi*fr))^2; % Spreading loss index
Rs = B * log2(1 + (P_S * beta * (d-x1)^(-alpha) * exp(-K * (d-x1))) / sigma);
Rm = B * log2(1 + (P_M * (N_L^2) * N_M * (beta * (d-x0)^(-alpha) * exp(-K * (d-x0))) * (beta * x2^(-alpha) * exp(-K * x2))) / sigma);
R(k) = Rs * (sum2 + sum3) + Rm * (1 - (sum2 + sum3));
end
plot(x0_range, R)
xlabel('SBS-user Distance, x0')
ylabel('Achievable Rate')
@Mathieu NOE.....x2 is fixed and independent of x0......MBS is another basestation in the system model.
Okey, intersteing results!.
But, I am a bit confused here if I should show the results with x0_range or d_range?
Imaybe you want the same plot for multiple d values so like this
NB that now the x axis is a ratio x0/d (normalized distance) so the curves can overlay in a meaningfull way
close all; clear all; clc;
% System parameters
F = 10000; % Number of files
S = 100; % SBS cache capacity (set to 100)
M = 50; % Cash capacity fraction
alpha = 2; % Path loss exponent for LOS link
c = 3e8; % Light speed
fr = 1e12; % Operating frequency
B = 10e6; % System bandwidth
epsilon = 0.8; % Skewness factor
K = 0.0016; % Molecular absorption coefficient
P_M = 10^(64/10); % Transmit power MBS
P_S = 10^(30/10); % Transmit power SBS
sigma = 10^(-90/10); % Noise power
N_L = 512;
N_M = 16;
eta = 1;
x2 =30; % RIS-MBS distance
d_range = (20:10:60);
for i = 1:numel(d_range)
d = d_range(i);
x0_range = linspace(0.01*d,0.99*d,100);
R = zeros(1,numel(x0_range));
for k = 1:numel(x0_range)
x0 = x0_range(k);
x1 = d-x0; % added line
%sum1 computation
f = 1:F;
sum1 = sum(f.^(-epsilon));
%sum2 computation
f = 1:M;
sum2 = sum(f.^(-epsilon))/sum1;
%sum computation
f = (M + 1):(M + (S - M) / eta);
sum3 = eta*sum(f.^(-epsilon))/sum1;
beta = (c/(4*pi*fr))^2; % Spreading loss index
Rs = B * log2(1 + (P_S * beta * (d-x1)^(-alpha) * exp(-K * (d-x1))) / sigma);
Rm = B * log2(1 + (P_M * (N_L^2) * N_M * (beta * (d-x0)^(-alpha) * exp(-K * (d-x0))) * (beta * x2^(-alpha) * exp(-K * x2))) / sigma);
R(k) = Rs * (sum2 + sum3) + Rm * (1 - (sum2 + sum3));
end
leg{i} = ['d = ' num2str(d)];
plot(x0_range/d, R)
hold on
end
legend(leg);
xlabel('SBS-user normalized Distance, x0/d')
ylabel('Achievable Rate')
Thank you @Mathieu NOE....this is what I want.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Genomics and Next Generation Sequencing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by