# Having difficult time trying to plot a simple trajecory

Tags:
1. May 30, 2014

### mesa

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. May 30, 2014

### SteamKing

Staff Emeritus
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

3. May 30, 2014

### jbunniii

Just don't make the all too common error of redefining $i$ if your code uses complex numbers.

4. May 30, 2014

### mesa

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
5. May 30, 2014

### mesa

Got it, :P
This is a fickle program, grrrrrr

6. Jun 17, 2014

### mesa

I take that back, this is a wonderful program.

7. Jun 17, 2014

### Bill Simpson

That is perhaps because so many students use the internet to get their programming assignments done for them :)

8. Jun 18, 2014

### mesa

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 :)