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

Click For Summary
SUMMARY

The discussion focuses on resolving loop stuck issues in MATLAB's shooting method for projectile angle determination. The user encounters a problem where the angle values oscillate between two values for specific distances and initial velocities. A solution involves implementing a check to exit the while loop if subsequent angle calculations do not bring the projectile closer to the target distance. The suggestion emphasizes that using a try-catch block is not appropriate for this scenario, as it is meant for error handling rather than loop control.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Knowledge of the shooting method for projectile motion
  • Familiarity with while loops and control flow in programming
  • Basic concepts of projectile motion and angle calculations
NEXT STEPS
  • Implement a loop exit condition based on proximity to the target distance in MATLAB
  • Explore MATLAB's debugging tools to monitor variable changes during loop execution
  • Research the mathematical principles behind projectile motion and angle optimization
  • Learn about MATLAB error handling and when to use try-catch blocks effectively
USEFUL FOR

This discussion is beneficial for MATLAB programmers, physics students, and engineers working on projectile motion simulations or optimization problems involving angle calculations.

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 4 ·
Replies
4
Views
7K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K