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

Having difficult time trying to plot a simple trajecory

Tags:
  1. May 30, 2014 #1
    Hello all, I am trying to plot a simple trajectory in MATlab. Here is the code I wrote,

    v0 = 100;
    theta = pi/4;
    t=0:0.1:20;
    horizontal(t)=t.*v0.*cos(theta)
    vertical(t)=t.*v0.*sin(theta)-4.905.*t.^2
    %teacher gone missing, again, ARRRGGHHH!!!!!!
    title('Ballistic Trajectory of a Projectile'), xlabel('horizontal distance, m'), ylabel('vertical distance, m')
    plot (t,horizontal(t))

    I am getting this error,

    "Subscript indices must either be real positive integers or logicals."

    If I input individual values for 't' it produces the correct results up until the vertical distance reaches it's 'maximum' but do not know why?
     
  2. jcsd
  3. May 30, 2014 #2

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    If 'horizontal (t)' and 'vertical (t)' are supposed to be arrays rather than functions of 't', then the error message would make sense.

    To keep Matlab happy, why don't you use a dummy array index variable 'i' instead of t. Start with i = 1 and t = 0.0, and then t = (i - 1)*0.1
     
  4. May 30, 2014 #3

    jbunniii

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    Just don't make the all too common error of redefining ##i## if your code uses complex numbers. :biggrin:
     
  5. May 30, 2014 #4
    I'm new to Matlab so I am not sure what you mean by 'dummy array index variable' (this is not in my book). I do believe I see what you are getting at but we have been using,
    t=0:0.1:20
    and the lecturer is a jerk so anything outside what we go over, "...will result in a zero!!!" (has it plastered everywhere on the assignment).

    Anyway, it isn't working for this plot so... :P
     
    Last edited: May 30, 2014
  6. May 30, 2014 #5
    Got it, :P
    This is a fickle program, grrrrrr
     
  7. Jun 17, 2014 #6
    I take that back, this is a wonderful program.
     
  8. Jun 17, 2014 #7
    That is perhaps because so many students use the internet to get their programming assignments done for them :)
     
  9. Jun 18, 2014 #8
    That could be the reasoning behind these criteria although it seems most students in this class genuinely want to know how to write code.

    A big part of the problem seems to be a Professor buried under departmental expectations that are unreasonable for a 1 credit hour course so with this new insight in mind I rescind my earlier comment about the lecturer; it is the department heads who are the jerks :)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Having difficult time trying to plot a simple trajecory
  1. Plot in real time (Replies: 9)

Loading...