oblique throw for golf ball
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Fe99
el 27 de Nov. de 2020
Editada: Alan Stevens
el 28 de Nov. de 2020
I had the task of writing a program that will calculate the following for the golf ball:
1.Calculated and printed the angles and initial velocities at which the ball falls on the field.
2.Calculated and printed the angles and initial velocities at which the ball falls into the hole (hole in one). Printed travel time of the ball and plot the path of the balls.
3.Calculated the maximum height and maximum range of the ball for given data.
Given data:
The distance between the ball and the hole is 100m.
The size of the field is a circle 5m in diameter and the hole is in the middle.
Ф =[15:60] (angle) and Vo =[15:60] initial velocity
I have already written the code for the first part of the task but it stops for me in the second part wher ball fall direct in hole. I try use elseif D == 100 but more than obvious I didn’t tackle it the right way.
clear all
close all
clc
%1
v0 = [15:60]; %initial speed
a = [15:60]; %angle
g = 9.81; %gravitational acceleration
l = 100; %distance from ball to hole
fprintf('the ball falls on the field in the following cases:\n');
for i = 1:length(v0)
for j = 1:length(a)
D = (v0(i)^2*sind(2*a(j)))/g;
if D>=97.5 && D<=102.5
fprintf('Vo = %.2f m/s | angle = %.2f° | D = %.2f \n',v0(i),a(j), D);
elseif D==l %here is my problem :(
fprintf('HOLE IN ONE! Vo = %.2f m/s | angle = %.2f° | D = %.2f \n',v0(i),a(j), D);
end
end
end
0 comentarios
Respuesta aceptada
Alan Stevens
el 28 de Nov. de 2020
Editada: Alan Stevens
el 28 de Nov. de 2020
A little more like this perhaps:
v0 = [15:60]; %initial speed
a = [15:60]; %angle
g = 9.81; %gravitational acceleration
l = 100; %distance from ball to hole
fprintf('the ball falls on the field in the following cases:\n');
for i = 1:length(v0)
for j = 1:length(a)
D = (v0(i)^2*sind(2*a(j)))/g;
if D>=97.5 && D<=102.5
fprintf('Vo = %.2f m/s | angle = %.2f° | D = %.2f \n',v0(i),a(j), D);
end %Need new if because 100 falls between 97.5 and 102.5
if abs(D-l)<0.5 % Never test for exact equality with floating point numbers
fprintf('HOLE IN ONE! Vo = %.2f m/s | angle = %.2f° | D = %.2f \n',v0(i),a(j), D);
end
end
end
To reduce the coarseness of the test abs(D-l)<0.5 to, say, abs(D-l)< 0.1, you will need to decrease the values of the step sizes for v0 and a.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Function Creation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!