I want this for loop to dispaly the smallest calculated value of PE. What would be the best way of going about this?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
for t1 = 0:1:90,t2 = 0:1:90;
t1;
t2;
h1 = -b1*cosd(t1);
h2 = -(b1*cosd(t1)+b2*cosd(t2));
d1 = sqrt((x1-a1*sind(t1)).^2 + (y1+a1*cosd(t1)).^2)-L1;
d2 = sqrt((x1-(b1*sind(t1)+a2*sind(t2))).^2+(y2+(b1*cosd(t1)+a1*cosd(t2))).^2)-L2;
PE = (1/2)*k1*d1.^2 + w1*h1 - f1*b1*sind(t1) + (1/2)*k2*d2.^2 + w2*h2 - f2*(b1*sind(t1)+b2*sind(t2));
if PE == min
disp PE
end
end
0 comentarios
Respuestas (1)
Jeff Miller
el 28 de Mzo. de 2021
% something like this:
minPE = realmax;
for t1 = 0:1:90,t2 = 0:1:90;
t1;
t2;
h1 = -b1*cosd(t1);
h2 = -(b1*cosd(t1)+b2*cosd(t2));
d1 = sqrt((x1-a1*sind(t1)).^2 + (y1+a1*cosd(t1)).^2)-L1;
d2 = sqrt((x1-(b1*sind(t1)+a2*sind(t2))).^2+(y2+(b1*cosd(t1)+a1*cosd(t2))).^2)-L2;
PE = (1/2)*k1*d1.^2 + w1*h1 - f1*b1*sind(t1) + (1/2)*k2*d2.^2 + w2*h2 - f2*(b1*sind(t1)+b2*sind(t2));
if PE < minPE
minPE = PE;
end
end
disp minPE
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!