I want this for loop to dispaly the smallest calculated value of PE. What would be the best way of going about this?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Jeff Miller
am 28 Mär. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!