adding a for loop for a super simple code
9 views (last 30 days)
Show older comments
I am trying to add a for loop to determine if the result of my dist equation are greater than or less than 100 yards, then displaying whether it made across or not. I am however illiterate when it comes to coding. I got up to this and need some basic help on how to integrate a for loop here for this application, or if I should use something else
disp('A ball is launched on a football field, does it clear the whole field?');
Vi = input('How fast is the ball released in mph? ');
A = input('At what angle do you release this ball in degrees? ');
V_mps = (Vi/0.44704);
A_rad = A*(pi/180);
t_hit = 2*(V_mps/9.8)*sin(A_rad);
t_max = t_hit/2;
dist = V_mps*t_hit*cos(A_rad);
0 Comments
Answers (1)
Voss
on 7 Dec 2021
If I understand correctly, it seems like you can say:
if dist >= 100 % 100 meters, assuming your unit conversions are ok. convert 100 yards to the same units of dist to compare dist to 100 yards instead.
display('made it');
else
display('did not make it');
end
2 Comments
Voss
on 8 Dec 2021
No problem. Please mark my answer as accepted, if you don't mind. I appreciate it.
And BTW, everybody's got to start somewhere! Solving programming problems in an engineering program is probably an ideal way to get good at coding. And if you get stuck, someone here will be able to help out.
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!