I have a question on how to write the code to find two angles that allow a projectile to shoot at 90 metres. I have a function that calculates the horizontal distance with the given variables of the problem. If you imagine a graph that has the Angles from 0d to 90d on the x axis, and the horizontal angle corresponding to that angle, you get a parabola. I have two angles that give me a distance of 90 m. I am required to use the Bisector Method to find both these angles.
My first approach at this problem was the following:
V0 = 45; Starting Velocity
Cd = 0.5; Coefficient of Drag
mass = 0.145; Mass of Ball
area = 42; Area of Ball
tstep = 0.005; Time Step
start = 0; Starting Angle
finish = 90; Ending Angle
a = 1; % My error script to count for the while loop
while a > 0.05
left = start;
right = finish;
mid = (left + right)/2; % Calculation for the mid point during iterations
YL = ballistic(left, V0, Cd, mass, area, tstep, plotting);
YR = ballistic(right, V0, Cd, mass, area, tstep, plotting);
Ymid = ballistic(mid, V0, Cd, mass, area, tstep, plotting);
if YL < 90
left = mid;
elseif Ymid < 90
left = mid;
a = abs(Ymid - 90);
end
theta = mid;
maxdist = Ymid;
end
With the variables above, I would use a function called ballistic to calculate the distance that I would get with the angles given. Now I would have a while loop for the first angle and a while loop for the second angle and calculate the left distance and right distance and find the average. Depending on the result of the error (a) then it would do it again until it found the angle, but it is not working for me and/or don't know how to write the if statement construction. Can I please get some assistance writting this code please? Also, I am very new to MatLab so I would appreciate as much detail on how to solve this problem as possible. I think I am at a point where I do not know what or how to write what I am thinking about.
Angle vs Horizontal Distance Diagram
Thank you
Aucun commentaire:
Enregistrer un commentaire