How do I use the max() function on an optimization expression when using the genetic algorithm?
Afficher commentaires plus anciens
I am using the genetic algorithm to optimize a 5 by 5 planar antenna array in the aim of achieving a predetermined sidelobe level (SLL_imp in the following code) with as few antenna elements as possible. Moreover, the optimization variable is a 5 by 5 binary matrix (A_mn in the following code) which represents the state (either included or eliminated) of the individual antenna elements. However, I am getting an 'Invalid data type' error when I use max() on AF (an optimization expression in the following code that will be ultimately used to construct the objective/error function). How can I get around this problem?
% Sparse array optimization using GA
clear, clc
% Create binary optimization variables
A_mn = optimvar('A_mn',5,5,'Type','integer','LowerBound',0,'UpperBound',1);
% Create an optimization problem with the objective function
prob = optimproblem("Objective",error_fcn(A_mn));
options = optimoptions("ga","PlotFcn","gaplotbestf");
rng default % For reproducibility
[sol,fval,exitflag] = solve(prob,"Solver","ga","Options",options);
function y = error_fcn(A_mn)
% Define some variables to be used in AF (array factor) computation
j = sqrt(-1);
M = 5; N = 5;
f = 5.4e+9;
c = (3e+8)/sqrt(1);
lambda = c/f;
k = (2*pi)/lambda;
d_x = 0.5*lambda;
d_y = 0.5*lambda;
theta = linspace(-180, 180, 1001);
phi = 0;
theta_0 = 0;
phi_0 = 0;
beta_x = -k*d_x*sind(theta_0)*cosd(phi_0);
beta_y = -k*d_y*sind(theta_0)*sind(phi_0);
psi_x = k*d_x*sind(theta).*cosd(phi) + beta_x;
psi_y = k*d_y*sind(theta).*sind(phi) + beta_y;
% Compute the AF (array factor)
AF = 0;
for n = 1:N
for m = 1:M
AF = AF + (exp(j*((m-1)*psi_x + (n-1)*psi_y)));
end
end
AF_mag = abs(AF);
AF = 0;
for n = 1:N
for m = 1:M
AF = AF + (A_mn(m,n)*AF_mag);
end
end
% Compute the normalized AF (array factor) in decibel
AF_max = max(AF); % ERROR OCCURS ON THIS LINE
AF_dB = 20*log10(AF/AF_max);
% Find the sidelobes of the AF (array factor)
lobes = findpeaks(AF_dB);
% Identify the maximum sidelobe level
SLL = lobes(floor(0.5*length(lobes)));
SLL_imp = -12.0425; % the imposed sidelobe level that we want to optimize for
y = (SLL - SLL_imp)^2;
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!