plotting projectile with drag
Show older comments
I have a script to plot the projectile motion path with drag. However, the plot comes out as with no drag. Using parameter v0=150,h=10,dt=0.01,theta=0.1745
I think the mistake is in my while loop, buti can't figure it out.
function [rx,ry,vx,vy]=solve_ode_euler(v0,h,dt,theta)
n=1000; %number of maximum iterations
rho=1.225;
cd=0.479;
m=5.5;
D=0.1;
R=D/2;
A=4*pi*R^4;
g=9.81;
% initializing values of distance and velocity
rx(1)=0;
ry(1)=h;
v(1)=v0;
vx=v0*cos(theta);
vy=v0*sin(theta);
vx(1)=vx;
vy(1)=vy;
k=cd*rho*A/(2*m);
t(1)=0;
i=1;
dt=0.01;
% while loop to solve projectile with Euler method
while i<n
v(i+1)=sqrt((vx(i)^2)+(vy(i)^2)); % velocity magnitude as a vector
rx(i+1)=rx(i)+vx(i)*dt;
vx(i+1)=vx(i)-(k*v(i)*vx(i))*dt;
ry(i+1)=ry(i)+vy(i)*dt;
vy(i+1)=vy(i)-g*dt-(k*v(i)*vy(i))*dt;
t(i+1)=t(i)+dt;
if ry(i+1)<0 %stops the projectile if reaches the ground
i=n;
else
i=i+1;
end
plot(rx,ry)
end
1 Comment
Vongani PASCALINE MABASA
on 24 Jul 2021
I have excel data. How do I do the drag coding
Accepted Answer
More Answers (2)
the cyclist
on 13 Dec 2018
If I increase cd to a very large value, for example
cd=10000;
then I see the impact of drag -- the trajectory is no longer a parabola.
My guess is that you have a units problem, and some parameters is off by orders of magnitude.
Categories
Find more on Physics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!