Having difficult time trying to plot a simple trajecory

In summary: 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
  • #1
mesa
Gold Member
695
38
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
  • #2
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
Just don't make the all too common error of redefining ##i## if your code uses complex numbers. :biggrin:
 
  • #4
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:
  • #5
Got it, :P
This is a fickle program, grrrrrr
 
  • #6
mesa said:
Got it, :P
This is a fickle program, grrrrrr

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

What is a trajectory?

A trajectory is the path that an object takes through space and time. It can be described as a series of positions and velocities over a period of time.

Why is it important to plot a trajectory?

Plotting a trajectory is important because it allows us to visualize the motion of an object and better understand its behavior. It can also help us make predictions and analyze data.

What are the basic steps for plotting a trajectory?

The basic steps for plotting a trajectory include identifying the initial and final positions of the object, determining the time interval, calculating the velocity and acceleration, and using equations of motion to plot the points on a graph.

What are some common challenges when plotting a trajectory?

Some common challenges when plotting a trajectory include accounting for external forces such as air resistance, making accurate measurements of position and time, and dealing with complex motion such as curves or changes in direction.

What are some resources for help with plotting a trajectory?

There are many resources available for help with plotting a trajectory, including textbooks, online tutorials, and physics forums. It can also be helpful to consult with a teacher, mentor, or fellow scientist for guidance and advice.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
737
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
811
Back
Top