How to plot trajectory
4 views (last 30 days)
Show older comments
We were asked to plot the trajectory of a diver off a diving board, and I am having trouble getting my graph to publish for this problem. Can anyone tell me what I have done wrong? Thank you.
if true
t=2.5; %in seconds
Vox=2
Voy=8.25
tx=0:.1:2.5; %this will give me an array for the time of the diver in the x position
ty=0:.1:2.5; %this will give the array for the time of the diver in the y-position
function [tx,ty]= trajectory(Vox,Voy,tx,g)%function for varying angle
x=Vox*cos(0)*tx; %gives the position of the x
y=Voy*(sin(0)*ty)-(.5*g*(ty.^2)); %gives the position of the y
plot (x,y)
end
end
0 Comments
Answers (1)
Star Strider
on 4 Oct 2018
Your ‘trajectory’ function wants ‘ty’ as well, so you need to include that in the argument list. Other than that, you need to call it correctly.
Try this:
g = 9.81;
t=2.5; %in seconds
Vox=2;
Voy=8.25;
tx=0:.1:2.5; %this will give me an array for the time of the diver in the x position
ty=0:.1:2.5; %this will give the array for the time of the diver in the y-position
function [tx,ty]= trajectory(Vox,Voy,tx,ty,g)%function for varying angle
x=Vox*cos(0)*tx; %gives the position of the x
y=Voy*(sin(0)*ty)-(.5*g*(ty.^2)); %gives the position of the y
plot (x,y)
end
[tx,ty] = trajectory(Vox,Voy,tx,ty,g);
When I run it, it produces an acceptable plot.
Also, if you want ‘trajectory’ to return the calculated values for ‘x’ and ‘y’, you need to tell it.
Consider:
function [x,y] = trajectory(Vox,Voy,tx,ty,g)%function for varying angle
1 Comment
Drishya Dinesh
on 2 Dec 2020
Edited: Drishya Dinesh
on 2 Dec 2020
can i get a time varying trajectory for an aerial vehicle in 3d (6 dof motion- x,y,z,phi,theta,psi)? Even helical is fine
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!