Having difficult time trying to plot a simple trajecory

AI Thread Summary
The discussion revolves around a user attempting to plot a simple trajectory in MATLAB but encountering an error related to subscript indices. The error arises because the user is treating 'horizontal(t)' and 'vertical(t)' as functions rather than arrays. Suggestions include using a dummy array index variable instead of 't' to resolve the issue. The user expresses frustration with the lecturer's strict adherence to course material, which limits exploration of solutions outside the taught methods. Overall, the conversation highlights challenges faced by students in programming courses and the pressures from academic expectations.
mesa
Gold Member
Messages
694
Reaction score
36
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?
 
Physics news on Phys.org
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
 
Just don't make the all too common error of redefining ##i## if your code uses complex numbers. :biggrin:
 
SteamKing said:
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

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:
Got it, :P
This is a fickle program, grrrrrr
 
mesa said:
Got it, :P
This is a fickle program, grrrrrr

I take that back, this is a wonderful program.
 
mesa said:
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).

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

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

Similar threads

Replies
8
Views
2K
Replies
1
Views
2K
Replies
4
Views
2K
Replies
1
Views
3K
Replies
6
Views
2K
Replies
4
Views
2K
Replies
6
Views
3K
Replies
1
Views
2K
Back
Top