Having difficult time trying to plot a simple trajecory

Click For Summary

Discussion Overview

The discussion revolves around a participant's difficulty in plotting a simple trajectory in MATLAB, focusing on coding issues and error messages encountered during the process. The scope includes technical explanations related to programming and debugging in MATLAB.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • A participant shares their MATLAB code for plotting a projectile's trajectory and describes an error message related to subscript indices.
  • Some participants suggest that the error may stem from treating 'horizontal(t)' and 'vertical(t)' as functions rather than arrays, proposing the use of a dummy index variable instead of 't'.
  • One participant expresses confusion about the suggestion of using a dummy array index variable, indicating they are new to MATLAB and concerned about adhering to course guidelines.
  • Another participant humorously warns against redefining the index variable if complex numbers are involved.
  • There are expressions of frustration with the MATLAB program, with mixed sentiments about its usability.
  • Participants discuss the pressures of academic expectations and the challenges posed by the course structure and teaching methods.

Areas of Agreement / Disagreement

Participants express varying levels of understanding and frustration regarding MATLAB and the course structure. There is no consensus on the best approach to resolve the coding issue, and multiple viewpoints on the teaching methods and departmental expectations are presented.

Contextual Notes

Participants mention specific course constraints and expectations that may limit their ability to explore solutions outside of what has been taught in class.

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 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K