Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

A simple problem with matlab code

  1. Dec 8, 2009 #1
    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. jcsd
  3. Dec 8, 2009 #2

    Mark44

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: A simple problem with matlab code
  1. Simple Matlab (Replies: 2)

Loading...