Effacer les filtres
Effacer les filtres

use optimizer for separated area

1 vue (au cours des 30 derniers jours)
koorosh dastan
koorosh dastan le 3 Oct 2023
Commenté : koorosh dastan le 28 Nov 2023
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 commentaires
Alan Weiss
Alan Weiss le 3 Oct 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
koorosh dastan
koorosh dastan le 28 Nov 2023
i explained more here
elementNumb=20;
random_numbersw = rand(1,elementNumb); % Random number from 0 to 1
ubb=90;
lbb=-90;
random_numberst = lbb + (ubb + ubb) * rand(1, elementNumb); % Random number from -90 to 90
% random_numberst = 20*(ones(1 , elementNumb));
x0 = [ random_numbersw,random_numberst ] ;
ub = zeros(1, elementNumb*2); % Initialize a matrix of zeros with 40 elements
ub(1:elementNumb) = 1; % Set values from 1 to 21 to 0
ub(elementNumb+1:elementNumb*2) = ubb; % Set values from 22 to 40 to 90
lb = zeros(1, elementNumb*2); % Initialize a matrix of zeros with 40 elements
lb(1:elementNumb) = 0; % Set values from 1 to 21 to 0
lb(elementNumb+1:elementNumb*2) = lbb; % Set values from 22 to 40 to 90
%%
%%Fminimax
options=optimset('disp','iter','LargeScale','off','Diagnostics',...
'on','TolFun',.000000001,'MaxIter',1000000,'MaxFunEvals',100000);
[x,fval,maxfval,exitflag,output,lambda] = fminimax(@costy,x0,[],[],[],[],lb,ub,[],options);
%%
%%function
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.1;
teta1 = ((-60) :step: (-25));
teta2 = ((-25) :step: (11));
teta3 = ((15) :step: (20));
teta4 = ((25) :step: (50));
teta5 = ((50) :step: (60));
tetat = [teta1,teta2,teta3,teta4,teta5];
lenteta1 = length(teta1);
sumLenteta12 = length(teta1) + length(teta2);
sumLenteta123 = length(teta3) + sumLenteta12;
sumLenteta1234 = sumLenteta123 + length(teta4);
g = zeros(elementNumb,length(tetat));
for h = 1:elementNumb
%%teta1
for aa = 1:length(teta1)
g(h,aa) = g(h,aa)+(deltaTeta(h) * ( exp(j*(h-1) * (k*d*sind(teta1(aa)+deltaTeta(h+elementNumb)))))); %w W
end
%
%%teta2
for bb=(lenteta1+1):(sumLenteta12)
g(h,bb) =g(h,bb)+( deltaTeta(h) * exp(j*(h-1) * (k*d*sind(teta2(bb-lenteta1)+deltaTeta(h+elementNumb))))); %with W
end
%%teta3
for cc = (sumLenteta12+1):(length(teta3)+sumLenteta12)
g(h,cc) = g(h,cc)+(-(( deltaTeta(h) * exp(j*(h-1) * (k*d*sind(teta3(cc-sumLenteta12)...
+deltaTeta(h+elementNumb))))))); %w W
end
%%teta4
for dd = (sumLenteta123+1):(sumLenteta123+length(teta4))
g(h,dd) = g(h,dd)+( deltaTeta(h) * exp(j*(h-1) * (k*d*sind(teta4(dd-(sumLenteta123))...
+deltaTeta(h+elementNumb))))); %w W
end
%teta5
for ee = (sumLenteta1234+1):(sumLenteta1234+length(teta5))
g(h,ee) = g(h,ee)+( deltaTeta(h) * exp(j*(h-1) * (k*d*sind(teta5(ee-(sumLenteta1234))...
+deltaTeta(h+elementNumb))))); %w W
end
end
y = abs(sum(g,1));
end
i have 5 area (teta) i want my function be in one area max and in another are min
this area is teta3 so i think i should add minus(-) or i should inverse(1/) cost function
but when i add (-) nothing happen or when inverse i got alot of warning

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by