[Reddit Cross Post] Filtering results with small divergence

28 visualizaciones (últimos 30 días)
Toshiaki Takeuchi
Toshiaki Takeuchi el 15 de Oct. de 2025 a las 17:06
Respondida: Sam Chak el 17 de Oct. de 2025 a las 8:41
Hello, I am currently working on a calculator for composite materials, due to the nature of composite materials, they have different mechanical properties regarding their respective angle when plied together. I am trying to filter the plies that have similar mechanical properties so I can extract them for my work. Example if Q1=100, Q2=100,1 Q3=100,5 Q4=200 Q5=205. The plies Q1,Q2,Q3 are similar and processing them in my further calculations creates an excessive computational strain that is not needed. How can I code the program to choose the Q3,Q4,Q5 values and discard the other ones? Any tip, video or anything else will be greatly appreciated. Thank you in advance!

Respuesta aceptada

Sam Chak
Sam Chak el 17 de Oct. de 2025 a las 8:41
Are you looking for something like this
% Case 1
Q = [100 100 100 200 205];
Qu = unique(Q)
Qu = 1×3
100 200 205
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
or something like this?
% Case 2
rng('default')
objfun = @(x) ((x - 100).*(x - 200).*(x - 205) + rand/1e4).^2;
options = optimoptions(@ga,'PopulationSize', 30, 'MaxGenerations', 60, 'Display', 'off');
for i = 1:5
xSol(i) = ga(objfun, 1, [], [], [], [], 0, 300, [], options);
end
disp(xSol)
204.9955 204.9792 99.9858 199.9985 205.0545
Xsol = [100, 200, 205];
for j = 1:numel(xSol)
TF = isapprox(xSol(j), Xsol, AbsoluteTolerance=2e-2);
if sum(TF) == 1
Q(j) = xSol(j);
else
Q(j) = 0;
end
end
Q_solution = Q(Q ~= 0);
disp(Q_solution)
204.9955 99.9858 199.9985
round(Q_solution)
ans = 1×3
205 100 200
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Más respuestas (0)

Categorías

Más información sobre Historical Contests en Help Center y File Exchange.

Productos


Versión

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by