Maximum Velocity Problem

Mar 30, 2009 at 5:36pm
I am completely lost on this one - I've been told I'm making it too hard, but I'm still not seeing it...
I'm not asking for a complete answer, any help is appreciated - really stuck on where to begin.

We will look at a projectile (an object that is given an initial velocity at an angle with the horizontal). Our assumptions include that it moves only under the influence of gravity (after the initial velocity) and wind resistance which we will neglect. For our purposes we will ignore the effect of the shape of the object and spin.
You are to write a program that will calculate the maximum range (horizontal distance) at a user given initial velocity. The user will enter this in either meters per second or feet per second. Your program will need the user to specify which units they are using and make the calculations based on that information.
v0 is the initial velocity, R is the range and θ is the angle the projectile is sent.
We know that g = 9.81 m/s2 in SI (metric) and g = 32.174 ft/s2 . Your program needs to utilize a while loop starting your angle at 1 degree and incrementing by 1 degree until the maximum range is found (based on angle change). When you are calculating the sine of the angle realize that the default function of sine utilizes radians instead of degrees. To change degrees to radians multiply degrees times π and then divide by 180. If your user enters in feet per square second then your answer will be in feet whereas if they enter meters per square second your answer is in meters. Sample value to check operation of program: v = 27m/s will result in 74.3 meters at 45 degrees. Make sure your program works for both units.
Mar 30, 2009 at 7:37pm
Well, since you have an equation, you can simply solve for the zeroes of it (ignoring the negative values or 0 because that is where you started). Just plug in the different information each time, then record the angle/distance and check them.
Mar 30, 2009 at 7:57pm
Calculate the X and V velocities from the given angle and initial velocity using sin/cos:
1
2
double y_vel = sin( angle ) * initial_vel;
double x_vel = cos( angle ) * initial_vel;


I assume the object is to start at y_pos=0, so therefore you need to find out how many seconds pass until y_pos reaches 0 again (it will move up initially, but as gravity changes its velocity it will begin to move down again).

Once you know how many seconds that takes, you multiply that with the X velocity (which is unchanging because no forces oppose it in this problem) and you have the total distance traversed.

Repeat that for every angle between 1-89 degrees and record whichever one has the highest distance
Mar 30, 2009 at 8:56pm
The angle should always be 45 degrees ;)
Mar 30, 2009 at 9:18pm
I just did this because it sounded fun and I was bored.

csiz appars to be right -- with only gravity in consideration, 45 degrees seems like the magic number.

Also you don't have to consider y position, you can determine how long it takes the object to land by seeing how long it takes for the velocity to reach zero.

 
seconds = 2 * y_vel / gravity;


y_vel is in m/s and gravity is in m/s^2. (m/s) / (m/s^2) = s, so "y_vel / gravity" is how many seconds it takes for the object to reach velocity zero (peak height), and the *2 is because it will take just as long to descend from its max height as it did to ascend to it.

fun stuff.
Mar 31, 2009 at 6:46am
Nope csiz is not right. The question requires you to establish the elevation angle which will produce the max range for any given velocity by inspection of the ranges for angles of 1° thru ?° after which the range decreases. You need to place the projectile formulae in a for loop like:
for(int i=1;i<90;i++)
angle=i*180/Pi;
etc.
Don`t forget that all angles are in radians which = (180/Pi * radians)°
Incedentally V units are m/s or ft/s not /square second.
Mar 31, 2009 at 10:47am
As disch said distance= sx*2*sy/g in witch sx and sy is the initial speed on the x and y axis... these vx=v*cos angle ; vy =v*sin angle witch gives the final formula d=v*v*2/g *sin angle* cos angle witch has a max value when sin angle *cos angle is max.

Going on: sin^2 a+cos^2a=1 -> sin a = sqrt (1-cos^2 a)
sin a*cos a=cos a*sqrt(1-cos^2 a) = sqrt(cos^2 a-cos^4 a) = def = x
-> x*x=cos^2 a-cos^4 a; lets say cos^2 a =y than
x*x=y-y*y -> y*y-y+x*x=0; x*x has the max value when delta=0 -> 1-4*x*x=0 -> max x*x=1/4 -> max x=1/2

x=1/2 is the max value of sin angle * cos angle witch means the angle for this to be max must be 45 degrees

The final answer: max distance=v*v/g always for angle = 45 degrees

Although this is the most simple answer you must go through all the angles because the text says so but the result must always be 45 degrees, if its not 45 than you've done something wrong.
Last edited on Mar 31, 2009 at 10:49am
Mar 31, 2009 at 2:39pm
Incedentally V units are m/s or ft/s not /square second.


you are correct -- velocity is in m/s or f/s

however gravity is in m/s^2 or f/s^2 because gravity is a force, not a velocity -- it changes your velocity at a rate of 9.81 meters per second per second (m/s/s == m/s^2)
Mar 31, 2009 at 7:31pm
edit:this is getting out of topic, I think he solved the problem a while ago...
anyway
g is an acceleration not a force!

Um well generalizing this kind of problem to something that can't be calculated through equations, I found that storing the position, velocity, mass of an object and than modifying them in a loop will give an almost perfect trajectory for any kind of force, acceleration. sx+=f1x/m;sy+=f1y/m;x+=sx;y+=sy; there can be any number of forces and the movement will be correct in case you ever want to do something graphical or more complex(like 10 planets moving around)

Has anyone simulated movement differently? I never thought of something else than what I said earlier and I'm curious.
Last edited on Mar 31, 2009 at 7:35pm
Mar 31, 2009 at 7:47pm
whoops @ accelleration vs. force

I suck at technical terms. My main point was that it's not a velocity.
Apr 1, 2009 at 7:03pm
thanks for all the help!
I've been told the loop needs to solve for the range of 1˚, then solve for 2˚, compare that to range of previous angle, etc. When the range of the previous angle > range of the new angle, the loop stops.
buffbill is correct, but where does the "while" come into play in the while loop?
edit: what I meant to say is that the program is supposed to be written using a while loop

I am new to this, so I know some of this is probably not needed, but this is what i have so far (not very much :( ):

//Technical Problem 3 - Maximum range
#include <iostream>
using namespace std;

int main()
{
double iVelocity;
int gravity = g
cout << " Please enter Initial Velocity of projectile: ";
cin >> iVelocity;
double units
cout << " ft/sec (f) or meters/sec (m)? ";
cin >> units
if (units = f == F)
{
g = 32.174
}
if (units = m == M)
{
g = 9.81
}
Last edited on Apr 1, 2009 at 7:57pm
Apr 2, 2009 at 1:33am
Well you could do something like:

1
2
3
4
while(r>max_r)
{//calculate r here
if(r>max_r)max_r=r;
if(r<r_max)break;}//loop stops 


If a while loop is not mandatory you can use a for loop like:

1
2
3
4
5
6
7
8
for(int i=20;i<51;i++)//print: elevation (i),flight time(t),range(r) fo 30 elevs
{el=i;//elevation tabulated from 20° to 50°
vy=cos(i*Pi/180;//get vertical  velocity
ft=vy/(g/2);//get flight time
vx=sin(i*Pi/180);//get horizontal velocity
r=vx*ft;//get range.
cout<<el<<ft<<r<<endl;//print 30 rows by increasing elevation of 1°
}

Hope this helps
Topic archived. No new replies allowed.