Are the variables(fminimax) independent of each other?

1 visualizzazione (ultimi 30 giorni)
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
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)
Local minimum possible. Constraints satisfied. fminimax stopped because the predicted change in the objective function is less than the value of the function tolerance and constraints are satisfied to within the value of the constraint tolerance.
x = 1×68
0.0312 0.1603 0.4457 0.7698 0.9373 0.8714 0.7723 0.8110 0.9235 0.9144 0.8142 0.7950 0.9053 0.9845 0.8910 0.7986 0.8727 0.9780 0.9017 0.8312 0.8588 0.9048 0.9441 0.9236 0.8945 0.9359 0.9057 0.8616 0.8217 0.9628
fval = 1×301
1.0e-04 * 0.8228 0.5679 0.3519 0.2019 0.1991 0.3050 0.4229 0.5287 0.6181 0.6903 0.7459 0.7858 0.8111 0.8230 0.8226 0.8113 0.7902 0.7607 0.7240 0.6816 0.6348 0.5853 0.5349 0.4857 0.4403 0.4017 0.3734 0.3583 0.3583 0.3728
maxfval = 8.2763e-05
exitflag = 5
output = struct with fields:
iterations: 172 funcCount: 12614 lssteplength: 1 stepsize: 9.9380e-04 algorithm: 'active-set' firstorderopt: [] constrviolation: 5.5519e-07 message: 'Local minimum possible. Constraints satisfied.↵↵fminimax stopped because the predicted change in the objective function↵is less than the value of the function tolerance and constraints ↵are satisfied to within the value of the constraint tolerance.↵↵<stopping criteria details>↵↵Optimization stopped because the predicted change in the objective function,↵3.087656e-07, is less than options.FunctionTolerance = 1.000000e-06, and the maximum constraint↵violation, 5.551912e-07, is less than options.ConstraintTolerance = 1.000000e-06.'
lambda = struct with fields:
lower: [68×1 double] upper: [68×1 double] eqlin: [0×1 double] eqnonlin: [0×1 double] ineqlin: [0×1 double] ineqnonlin: [0×1 double]
[small, high] = bounds(x(elementNumb+1:end))
small = 11.4138
high = 12.0653
%%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
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)
Local minimum possible. Constraints satisfied. fminimax stopped because the predicted change in the objective function is less than the value of the function tolerance and constraints are satisfied to within the value of the constraint tolerance.
x = 1×68
0.0972 0.5383 0.1354 0.9782 0.1019 0.0312 1.0000 0.0315 0.2759 0.1363 0.2511 0.0383 0.4076 0.3231 0.1660 0.9462 0.0689 0.8245 0.7678 1.0000 0.3905 0.6368 0.5186 0.2140 0.6079 0.0312 0.0457 0.5096 0.0312 1.0000
fval = 1×301
0.0160 0.0041 0.0053 0.0112 0.0146 0.0160 0.0157 0.0140 0.0114 0.0084 0.0056 0.0045 0.0062 0.0089 0.0114 0.0135 0.0150 0.0159 0.0160 0.0155 0.0144 0.0129 0.0110 0.0091 0.0074 0.0065 0.0069 0.0082 0.0100 0.0118
maxfval = 0.0160
exitflag = 5
output = struct with fields:
iterations: 341 funcCount: 24543 lssteplength: 1 stepsize: 0.0155 algorithm: 'active-set' firstorderopt: [] constrviolation: 8.2747e-07 message: 'Local minimum possible. Constraints satisfied.↵↵fminimax stopped because the predicted change in the objective function↵is less than the value of the function tolerance and constraints ↵are satisfied to within the value of the constraint tolerance.↵↵<stopping criteria details>↵↵Optimization stopped because the predicted change in the objective function,↵8.003316e-07, is less than options.FunctionTolerance = 1.000000e-06, and the maximum constraint↵violation, 8.274655e-07, is less than options.ConstraintTolerance = 1.000000e-06.'
lambda = struct with fields:
lower: [68×1 double] upper: [68×1 double] eqlin: [0×1 double] eqnonlin: [0×1 double] ineqlin: [0×1 double] ineqnonlin: [0×1 double]
[small, high] = bounds(x(elementNumb+1:end))
small = -86.6930
high = 86.8862
%%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

Accedi per commentare.

Risposte (0)

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!

Translated by