MATLAB Plotting Maximum Height & Horizontal Distance

AI Thread Summary
The discussion revolves around troubleshooting a MATLAB script designed to calculate and plot the maximum height and horizontal distance of an object thrown at a speed of 10 m/s at varying angles from 0 to π/2. The initial code encounters an error due to the improper use of the "end" keyword and the undefined variable "y." A corrected version of the code is provided, which defines the angle variable as a range from 0 to π/2 and computes both distance and height correctly. The plot function is adjusted to display the horizontal distance and maximum height on the same axes. Additionally, there is a shift in topic towards preprocessing steps for extracting the fundamental frequency from a speech signal, indicating a need for clarity on audio processing techniques. The conversation highlights the importance of proper variable definition and syntax in MATLAB programming.
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
Views
2K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
2
Views
3K
Replies
2
Views
2K
Back
Top