Plotting Maximum Height & Horizontal Distance

Click For Summary

Discussion Overview

The discussion revolves around solving a MATLAB scripting problem related to plotting the maximum height and horizontal distance of an object thrown at a specific speed and angle. Participants explore the equations for distance and height, as well as troubleshooting coding errors.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant shares their MATLAB code and describes an error related to the use of the "end" keyword, indicating a misunderstanding of its context.
  • Another participant points out that the "end" keyword is incorrectly used without a corresponding "if" or "while" statement and notes that the variable "y" is undefined in the original code.
  • The second participant provides a corrected version of the code, suggesting a range for the angle variable and correcting the plotting commands.
  • A later reply expresses gratitude for the assistance, indicating that the provided solution resolved the issue.

Areas of Agreement / Disagreement

Participants generally agree on the corrections needed for the MATLAB code, with one participant successfully implementing the suggested changes. There is no disagreement present in this aspect of the discussion.

Contextual Notes

The original code lacked proper variable definitions and context for the "end" keyword, which may lead to confusion for those unfamiliar with MATLAB syntax.

Who May Find This Useful

This discussion may be useful for individuals learning MATLAB, particularly those interested in physics-related programming tasks involving projectile motion.

roam
Messages
1,265
Reaction score
12
I'm trying to solve the following problem using a MATLAB script but I keep getting an error:

Show on the same axes the maximum height and horizontal distance traveled for an object thrown at a speed of 10ms-1 at an angle ranging from 0 to π/2. Equation for distance & height are:

D= v2/g sin(2θ)

h= (v2/2g) sin2θ

g=9.81.

This is my code:

Code:
g=9.81; v=10;
t=pi/2;
D=(v^2/g)*sin(2*t);
h=(v^2/(2*g))*(sin(t)).^2;
end
plot([0:t],D,'b',[0:t],y,'*')
legend('horizontal distance','maximum height')

When I run this code the graph doesn't come up and I get the following error:

? Error: File: Untitled.m Line: 5 Column: 1
Illegal use of reserved keyword "end".

Any help here is very much appreciated. :smile:
 
Physics news on Phys.org
There is an "end" but nothing is started e.g. "if, while" etc. Also you did not define variable "y"

Code:
g=9.81; v=10;
t=0:0.1:pi/2;
D=(v^2/g)*sin(2*t);
h=(v^2/(2*g))*(sin(t)).^2;
plot(t,D,'b',t,h,'*')
legend('horizontal distance','maximum height')

This should work...
 
Pls help me..
what are the preprocessing steps to be performed on a speech (wav file)signal in order to extract the fundamental frequency accurately?
 
Thank you so much Trambolin, it worked! :smile:
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 11 ·
Replies
11
Views
5K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K