MATLAB: Numerical approximation of projectile motion with air resistance

air resistancenumerical approximationprojectile motion

For a school project, I need to estimate the maximum distance of a projectile without neglecting air resistance. I'm following the procedure outlined here:
On the second page it shows a nice, step by step process to find a numerical approximation. I am trying to reproduce the trajectory of the baseball that is shown on the last page in order to verify my model. However, the plot shows that the baseball will travel over 100 meters, while my model shows that it will travel about 80. Here is my code:
clear
clc
close all
%Constants for Baseball
m=.145 %kg
A=pi*(.0366*2)^2/4 %m^2
C=.5 %Drag Coefficient of a sphere
rho= 1.2 %kg/m^3 (density of air)
D=rho*C*A/2
g=9.81 %m/s^2 (acceleration due to gravity)
%Initial Conditions
delta_t= .001 %s
x(1)=0
y(1)=0
v=50 %m/s
theta=35 %deg
vx=v*cosd(theta)
vy=v*sind(theta)
t(1)=0
%Start Loop
i=1
while min(y)> -.001
ax=-(D/m)*v*vx;
ay=-g-(D/m)*v*vy;
vx=vx+ax*delta_t;
vy=vy+ay*delta_t;
x(i+1)=x(i)+vx*delta_t+.5*ax*delta_t^2;
y(i+1)=y(i)+vy*delta_t+.5*ay*delta_t^2;
t(i+1)=t(i)+delta_t;
i=i+1;
end
plot(x,y)
xlabel('x distance (m)')
ylabel('y distance (m)')
title('Projectile Path')
If anyone has a few minutes to take a look at this, I'd really appreciate it. I can't seem to find the problem. Thank you!

Best Answer

You are forgetting to update v inside your loop.
v = sqrt(vx^2 + vy^2);
Right now it is sitting at v = 50 the whole time.