Projectile Motion when y0 does not equal 0

4 次查看(过去 30 天)
For my dynamics class is was given an example command to plot the motion of a projectile;
clear all
close all
clc
g= -9.81; % gravitational acceleration
angle= 45 *pi/180 ; % angle in radian
v0= 2; % initial speed in m/s
y0=0;
x0=0;
v0y= v0* sin(angle); % vertical initial velocity
v0x= v0* cos(angle); % horz. initial velocity
tf= v0y /(-0.5*g ); % simulate until final time = tf second
t=[0:0.001:tf]; %define time grid for simulation
n=length(t); % number of element in vector t
for i=1:1:n
y(i)=y0+(v0y)*t(i)+0.5*g*(t(i))^2; % calculate vertical position at time t
x(i)=x0+(v0x)*t(i); % calculate horizontal position at time t
end
plot(x,y)
The problem is that I need to plot the motion of a projectile with a v0 of 150 and the y0 is eqaul to 150. I am able to plug all the correct information in and get it to plot the top half of the motion (150 up and back down to 150) but it wont plot the motion below 150 back down to 0 and I am wondering how I should get it to where it will. Any suggetions or ideas???
  1 个评论
Aidan
Aidan 2023-3-10
I should also add that the angle of the motion is based off a 3-4-5 triangle and the launch angle is 36.87 degrees

请先登录,再进行评论。

回答(2 个)

Torsten
Torsten 2023-3-10
移动:Torsten 2023-3-10
Solve y(t) = 0 for t and you'll find tf, the time when the projectile hits the ground.

Voss
Voss 2023-3-10
clear all
close all
clc
g= -9.81; % gravitational acceleration
angle= 45 *pi/180 ; % angle in radian
% v0=2; % initial speed in m/s
v0=150; % initial speed in m/s
y0=150;
x0=0;
v0y= v0* sin(angle); % vertical initial velocity
v0x= v0* cos(angle); % horz. initial velocity
% tf= v0y /(-0.5*g ); % simulate until final time = tf second
% equation for y(t): y(t) = y0 + v0y*t + 0.5*g*t^2
% you want to find the t where y(t) = 0, so call it tf and solve:
% y(tf) = y0 + v0y*tf + 0.5*g*tf^2 = 0
% for instance by applying the quadratic formula (and choose the
% "-" solution because the "+" solution gives a tf < 0):
tf = (-v0y-sqrt(v0y^2-4*0.5*g*y0))/(2*0.5*g)
tf = 22.9562
t=0:0.001:tf; %define time grid for simulation
n=length(t); % number of element in vector t
for i=1:1:n
y(i)=y0+v0y*t(i)+0.5*g*t(i)^2; % calculate vertical position at time t
x(i)=x0+v0x*t(i); % calculate horizontal position at time t
end
plot(x,y)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by