# A simple problem with matlab code

1. Dec 8, 2009

### CaspianTiger

Hi,

I am trying to use the shooting method to determine the angle of a projectile. However for some values of distance and initial velocity my value for angles get stuck between two values.
I want to put a piece of code into my shooting method which can either detect that my while loop has become stuck between two values or after a certain number of values offers an error message suggesting a different initial velocity for that distance.

I was thinking of using a try catch statement however i am not sure how these work and i am not sure how to state i want my error message to occur after a certain value of iterations of my while loop.

If you want my present code i can post it.

Any help would be great.

Thanks

2. Dec 8, 2009

### Staff: Mentor

A try ... catch block won't be of much use to you since these are used to trap errors such as division by zero and others.

Are the angles you get stuck on equidistant from 45 degrees? I.e., is one 45 degrees + alpha and the other one 45 degrees - alpha? For a given muzzle velocity, the maximum range comes when the projectile is fired at and angle of 45 degrees from the horizontal. All other angles produce a shorter distance, which means that for a given target distance that is less than the maximum range, there will be two angles that will place the projectile at that distance. I think that's what you're coming up against.

One way around this is to calculate how close the projectile is to its target. If you next angle value doesn't get you any closer to the target, exit the loop.