Effacer les filtres
Effacer les filtres

如何编写循环遍历变量所有组合的代码

4 vues (au cours des 30 derniers jours)
杨杨 蒋
杨杨 蒋 le 11 Mai 2023
Below is part of the code of my main function
IntCon = 3;
nonlcon = @yueshu;
options = optimoptions('ga','PlotFcn', {@gaplotbestf,@gaplotstopping},'Display','diagnose',...
'MaxStallGenerations',8,'FunctionTolerance',1e-3,'MaxGenerations',100,'PopulationSize',100);
fun = @youhua_ga1009;
lb = [0.0002 0.0002 5];
ub = [0.0003 0.0007 19];
rng default % For reproducibility
[x,fval,exitflag,output] = ga(fun,3,[],[],[],[],lb,ub,nonlcon,IntCon,options)
xlswrite([num2str(n),'output'],output_all);
end
This is part of the code of the objective function
function p_sum = youhua_ga1009(x)
%计算不同极齿尺寸和数量的耐压总和
% 此处显示详细说明
l_tooth=x(1);
h_tooth=x(2);
angle=0;
n_tooth=x(3);
step1 = 0.00001;
step2 = 0.00005;
step3 = 1;
for iii = x(1)
x(1) = lb(1):step1:ub(1);
for jjj = x(2)
x(2) = lb(2):step2:ub(2);
for kkk = x(3)
x(3) = lb(3):step3:ub(3);
I want to explore the solution under different combinations of all variables in the upper and lower limits of variables and step size conditions, but after writing the above for loop code in the objective function, the run has an error that cannot be assigned because the number of elements on the left and right is different, how to solve it

Réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!