Finding minimum value in while loop
7 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I would like to find the minimum value in what is calculated in while loop.
I have written a program so far...
speed=input("Enter the speed: ");
D=input("Enter the distance: ");
angle=5;
throwing_distance = (speed^2) * sin(pi * angle / 90) / 9.81;
deviation=abs(D-(speed^2) * sin(pi * angle / 90) / 9.81)
while angle<45
deviation=abs(D-(speed^2) * sin(pi * angle / 90) / 9.81);
angle=angle+1;
end
I would like to add if statement like,
if deviation is the minimum, display the angle.
I really appreciate if someone can help me solve this problem.
0 件のコメント
回答 (1 件)
Walter Roberson
2019 年 11 月 9 日
bestdeviation = inf;
while deviation < bestdeviation
bestdeviation = deviation;
deviation = abs(D-(speed^2) * sin(pi * angle / 90) / 9.81);
angle=angle+1;
end
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!