use optimizer for separated area
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
i wrote this code
close all
clear all
elementNumb=20;
ubb=90;
lbb=-90;
random_numberst = lbb + (ubb + ubb) * rand(1, elementNumb); % Random number from -90 to 90
x0 = ( random_numberst) ; %Initiat delta
ub = zeros(1, elementNumb); % Initialize a matrix of zeros with 40 elements
ub(1:elementNumb) = ubb; % Set values from 1 to 21 to 0
lb = zeros(1, elementNumb); % Initialize a matrix of zeros with 40 elements
lb(1:elementNumb) =lbb; % Set values from 1 to 21 to 0
[x,fval] = fminimax(@costy,x0,[],[],[],[],lb,ub);
function y = costy(deltaTeta)
freq = 9*10^9; %Freq
j = sqrt(-1); %Define Imaginary
l =(3*10^8)/freq; %Lambda
k = (2*pi)/l; %Constant
d = 0.5*l; %Distant of each element
elementNumb = 20;
step = 0.01;
teta1 = ((-1*90):step:(25));
teta2 = ((25):step:(28));
teta3 = ((28):step:(90));
tetat = [teta1,teta2,teta3];
% gg = length(teta1);
jj = length(teta1)+length(teta2);
y = zeros(size(tetat));
for h = 1:elementNumb
for t = 1:length(teta1)
y(t) = y(t)+1 * ( exp(j*(h-1) * (k*d*sind(teta1(t)+deltaTeta(h)))));
end
for hh = (length(teta2)+length(teta1)+1):(length(teta3)+length(teta2)+length(teta1))
y(hh) = y(hh)+ 1 * exp(j*(h-1) * (k*d*sind(teta3(hh-jj)+deltaTeta(h))));
end
end
end
as you can see i want to minimize some area that it doesnt min
then i run this code here
elementNumb=20;
deltaTeta=(x(1:20));
freq=9*10^9;
j=sqrt(-1);
l=(3*10^8)/freq;
k=(2*pi)/l;
d=0.5*l;
xas=90;
teta=((-1*xas):0.01:(1*xas));
% deltaTeta=zeros(elementNumb);
y=0;
% w=ones(elementNumb);
for h=1:elementNumb
y=y+exp(j*(h-1)*(k*d*sind(teta+deltaTeta(h))));
end
y=y/max(y);
figure;
%
plot(teta,20*log10(abs(y)),'k')
%
axis([-100 100 -100 2]);
but the answer is meaningless
the orginal figure is ( deltaTeta=zeros(elementNumb);)
you can see it maximize in 0 but i want change area to teta2
2 comentarios
Alan Weiss
el 3 de Oct. de 2023
I would have a better chance of understanding what you are trying to accomplish if you would explain in words what you are attempting. Are you trying to minimize or maximize something? Are you using an optimization solver to do so? You said
"as you can see i want to minimize some area that it doesnt min "
I don't know what that means. I see you have an fminimax call. What is the thing you are trying to minimax? Is it complex-valued? Optimization Toolbox solvers generally work only on real-valued functions (except for least-squares solvers).
Alan Weiss
MATLAB mathematical toolbox documentation
Respuestas (0)
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!