Could someone perhaps guide me in the right direction to figure out a way to start this code?

(Assignment) "Your program should also have a feature that predicts the velocities and elevation angles at which the projectile can be launched to hit a target given a specified distance. The input to this part of the program should be only the target distance. The output from this part of the program should be the velocities and launch angles for the projectile."
I don't see a way to get both those outputs by just inputting a distance. I'm not asking for someone to give me a code, but just a something to help me start.

3 Comments

Well, logically if you want to launch a projectile to land a certain distance away you can do so at a variety of angles, but the shallower the angle the less velocity you need otherwise it will travel too far, whereas the higher you send the projectile the more vertical distance it has to travel while also still travelling your desired horizontal distance.
I don't know the exact maths for it as it isn't a problem I am trying to solve myself, but simply in terms of the idea of getting the two outputs from the one input it seems quite clear.
I would guess there are an infinite number of [angle, velocity] pairs that achieve a given distance, but I may be wrong, I haven't done the maths.
I assume you have been studying projectile motion in class. So what equations are you familiar with for this motion? Forget the targeting aspects for the moment ... if you were simply given a velocity and an angle, could you write a program to predict its trajectory? Start with that. Once you have that working, then it shouldn't be too much work to extend it to a targeting program. See this link:
https://en.wikipedia.org/wiki/Projectile_motion
clc,clear
F = input('Targeted Distance = ');
V_o = input('Velocity at launch = ');
Theta = input('Elevation angle at launch = ');
a=-9.81; %Its a given
b=V_o*sind(Theta) %It makes the coding a bit less confusing.
c=0; %Also a given
fprintf('The targeted distance for the launch is %d meters. \n', F)
fprintf('The velocity for the launch is %d meters per second. \n', V_o)
fprintf('The elevation angle for the launch is %d degrees. \n', Theta);
Q1=(-b-sqrt(b^2-4*a*c))/(a); %The 1/2 and times 2 cross out for the denom
disp(Q1)
%%Horizontal Range
H = V_o*cosd(Theta)*(Q1);
fprintf('The Horizontal Range of the launch is %0.3f \n', H)
%%Vertical Height
V = (b^2)/(a*2)*2;
fprintf('The Vertical Height of the launch is %0.3f \n', V)

Sign in to comment.

Answers (1)

Hi Collin,
In this case there would be multiple velocity and launch angles. The formulae for projectile distance is
d=(v^2/g). sin(2.theta).
where v is initial velocity, g gravitational acceleration and theta is projection angle.
Now if d is given, then relation between v and theta will be,
v=sqrt(d.g.cosec(2.theta)).
Now, you can vary the theta from 1 to 90 degree in specific interval (e.g. 1 degree)and get corresponding velocities v and out the angle and their corresponding velocities in a table format.

3 Comments

velocities = linspace(8, 15, 1000); angles = linspace(10, 80, 1000);
d = sqrt((T*a)/(sind(2*angles)))
I get an error saying Matrix dimensions must agree, and i've googled how I would fix it, and nothing works.
Use '.*' and './' (element wise multiplication and division) instead of '*' and '/'
buttonNumber = menu ('Select the targeted distance','8','9','10','11','12','13','14','15');
T = buttonNumber + 7;
velocities = linspace(8, 15, 1000);
angles = linspace(10, 80, 1000);
[V, A] = meshgrid(velocities, angles);
distanceImage= (V^2./a)*sin(2.*velocities)
imshow(distanceImage, []);
hold on;
contour(V,A,distanceImage)
Ive made some changes.

Sign in to comment.

Asked:

on 21 Apr 2016

Commented:

on 28 Apr 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!