Finding minimum value in while loop
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Walter Roberson
am 9 Nov. 2019
bestdeviation = inf;
while deviation < bestdeviation
bestdeviation = deviation;
deviation = abs(D-(speed^2) * sin(pi * angle / 90) / 9.81);
angle=angle+1;
end
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!