Are the variables(fminimax) independent of each other?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
in this code i have 68 variable half of them between [0,1] and next half [-90,90]
the first half change reasonable but others dont change (almost 0.3) and dont go to minus area
are they related to each other?
% close all
clear all
elementNumb=34;
%%
%%with W
% random_numbersw = rand(1,elementNumb); % Random number from 0 to 1
random_numbersw = ones(1,elementNumb);
ubb=90;
lbb=-90;
% random_numberst = lbb + (ubb + ubb) * rand(1, elementNumb); % Random number from -90 to 90
random_numberst =12* (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.000001; % Set values from 1 to 21 to 0
lb(elementNumb+1:elementNumb*2) = lbb; % Set values from 22 to 40 to 90
%%
%%Fminimax
% options = optimoptions(@fminimax,'disp','iter','Diagnostics',...
% 'on', 'FiniteDifferenceStepSize',1e-3,...
% 'FunctionTolerance',1e-9,'MaxFunctionEvaluations',20000,'FunValCheck','on','ConstraintTolerance',0);
% options = optimoptions(@fminimax,'disp','iter','Diagnostics',...
% 'on',...
% 'FunctionTolerance',1e-9,'MaxFunctionEvaluations',2000,'FunValCheck','on');
% % options=optimset('disp','iter','LargeScale','off','Diagnostics',...
% 'on','TolFun',.00000000000001,'MaxIter',10000,'MaxFunEvals',1000000);
[x,fval,maxfval,exitflag,output,lambda] = fminimax(@costy,x0,[],[],[],[],lb,ub,[]);
%%function
function y = costy(x)
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 = 34;
step = 0.1;
teta1 = ((-80) :step: (-50));
tetat = teta1;
g = zeros(elementNumb,length(tetat));
for h = 1:elementNumb
for aa = 1:length(teta1)
g(h,aa) = g(h,aa)+(x(h) * ( exp(-j*(h-1) * (k*d*sind(teta1(aa)+x(h+elementNumb)))))); %w W
end
end
y = abs(sum(g,1));
end
and can they change with certain step for example first half 0.01 and second 5
4 Commenti
Walter Roberson
il 11 Dic 2023
You need to permit more iterations
elementNumb=34;
%%
%%with W
% random_numbersw = rand(1,elementNumb); % Random number from 0 to 1
random_numbersw = ones(1,elementNumb);
ubb=90;
lbb=-90;
% random_numberst = lbb + (ubb + ubb) * rand(1, elementNumb); % Random number from -90 to 90
random_numberst =12* (ones(1 , elementNumb));
x0 = [ random_numbersw,random_numberst ] ;
ub = zeros(1, elementNumb*2);
ub(1:elementNumb) = 1;
ub(elementNumb+1:elementNumb*2) = ubb;
lb = zeros(1, elementNumb*2);
lb(1:elementNumb) = 0.03125;
lb(elementNumb+1:elementNumb*2) = lbb;
%%
%%Fminimax
% options = optimoptions(@fminimax,'disp','iter','Diagnostics',...
% 'on', 'FiniteDifferenceStepSize',1e-3,...
% 'FunctionTolerance',1e-9,'MaxFunctionEvaluations',20000,'FunValCheck','on','ConstraintTolerance',0);
% options = optimoptions(@fminimax,'disp','iter','Diagnostics',...
% 'on','FiniteDifferenceStepSize',0.03125,...
% 'FunctionTolerance',1e-9,'MaxFunctionEvaluations',2000,'FunValCheck','on');
% % options=optimset('disp','iter','LargeScale','off','Diagnostics',...
% 'on','TolFun',.00000000000001,'MaxIter',10000,'MaxFunEvals',1000000);
options = optimoptions(@fminimax, 'MaxFunctionEvaluations', 20000, 'FunValCheck', 'on');
[x,fval,maxfval,exitflag,output,lambda] = fminimax(@costy,x0,[],[],[],[],lb,ub,[],options)
[small, high] = bounds(x(elementNumb+1:end))
%%function
function y = costy(x)
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 = 34;
step = 0.1;
teta1 = ((-80) :step: (-50));
tetat = teta1;
g = zeros(elementNumb,length(tetat));
for h = 1:elementNumb
x(h+elementNumb)=x(h+elementNumb);
for aa = 1:length(teta1)
g(h,aa) = g(h,aa)+(x(h) * ( exp(-j*(h-1) * (k*d*sind(teta1(aa)+x(h+elementNumb)))))); %w W
end
end
y = abs(sum(g,1));
end
Walter Roberson
il 11 Dic 2023
Modificato: Walter Roberson
il 11 Dic 2023
Note, however, that these fval are several orders of magnitude worse than the original fvals.
elementNumb=34;
%%
%%with W
rng(65432);
random_numbersw = rand(1,elementNumb); % Random number from 0 to 1
%random_numbersw = ones(1,elementNumb);
ubb=90;
lbb=-90;
random_numberst = lbb + (ubb + ubb) * rand(1, elementNumb); % Random number from -90 to 90
%random_numberst =12* (ones(1 , elementNumb));
x0 = [ random_numbersw,random_numberst ] ;
ub = zeros(1, elementNumb*2);
ub(1:elementNumb) = 1;
ub(elementNumb+1:elementNumb*2) = ubb;
lb = zeros(1, elementNumb*2);
lb(1:elementNumb) = 0.03125;
lb(elementNumb+1:elementNumb*2) = lbb;
%%
%%Fminimax
% options = optimoptions(@fminimax,'disp','iter','Diagnostics',...
% 'on', 'FiniteDifferenceStepSize',1e-3,...
% 'FunctionTolerance',1e-9,'MaxFunctionEvaluations',20000,'FunValCheck','on','ConstraintTolerance',0);
% options = optimoptions(@fminimax,'disp','iter','Diagnostics',...
% 'on','FiniteDifferenceStepSize',0.03125,...
% 'FunctionTolerance',1e-9,'MaxFunctionEvaluations',2000,'FunValCheck','on');
% % options=optimset('disp','iter','LargeScale','off','Diagnostics',...
% 'on','TolFun',.00000000000001,'MaxIter',10000,'MaxFunEvals',1000000);
options = optimoptions(@fminimax, 'MaxFunctionEvaluations', 1e6, 'FunValCheck', 'on');
[x,fval,maxfval,exitflag,output,lambda] = fminimax(@costy,x0,[],[],[],[],lb,ub,[],options)
[small, high] = bounds(x(elementNumb+1:end))
%%function
function y = costy(x)
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 = 34;
step = 0.1;
teta1 = ((-80) :step: (-50));
tetat = teta1;
g = zeros(elementNumb,length(tetat));
for h = 1:elementNumb
x(h+elementNumb)=x(h+elementNumb);
for aa = 1:length(teta1)
g(h,aa) = g(h,aa)+(x(h) * ( exp(-j*(h-1) * (k*d*sind(teta1(aa)+x(h+elementNumb)))))); %w W
end
end
y = abs(sum(g,1));
end
Risposte (0)
Vedere anche
Categorie
Scopri di più su Test Model Components in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!