MATLAB How Can I Resolve Loop Stuck Issues in MATLAB's Shooting Method?

Click For Summary
The discussion centers on resolving loop stuck issues in MATLAB's shooting method for projectile angle calculations. The user experiences a problem where the angle values become trapped between two numbers, particularly when trying to hit a specific distance with given initial velocities. Suggestions include checking if the angles are equidistant from 45 degrees, as this is the optimal angle for maximum range, leading to two possible angles for shorter distances. A proposed solution is to monitor the proximity of the projectile to the target and exit the loop if subsequent angle adjustments do not improve the distance. Overall, the focus is on improving the loop's functionality to avoid getting stuck on angle values.
CaspianTiger
Messages
16
Reaction score
0
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
 
Physics news on Phys.org
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.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K