I want this for loop to dispaly the smallest calculated value of PE. What would be the best way of going about this?

1 vue (au cours des 30 derniers jours)
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

Réponses (1)

Jeff Miller
Jeff Miller le 28 Mar 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

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by