use optimizer for separated area
이전 댓글 표시
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
Alan Weiss
2023년 10월 3일
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
koorosh dastan
2023년 11월 28일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!