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

조회 수: 1 (최근 30일)
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

답변 (1개)

Jeff Miller
Jeff Miller 2021년 3월 28일
% 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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by