I am trying to write a matlab code to model the projectile motion of a cannon shell including the effects of air drag and air density that changes with respect to temperature, however the code I have so far only computes a straight line for the shell trajectory which is incorrect. Can anyone point out where I have gone wrong and point me in the right direction to include the effect of air density and temperature? Thanks.
clear;
%input parameters
v0=input('Enter the muzzle velocity (m/s) ');
theta=input('Enter the quadrant elevation (degrees) ');
%T0=input('Enter the value for the ground temperature in degreees ');
%T0=T0+275.16;
b2bym0=4e-5;
g=9.8;
dt=1e-2;
%define initial conditions
x0=0;
y0=0;
vx0=v0*cosd(theta);
vy0=v0*sind(theta);
fdragx=-b2bym0*v0*vx0;
fdragy=-b2bym0*v0*vy0;
n=1000; %iterations
%Tratio=(T0/300)^(2.5);
%define data array
%t=zeros(1000);
x=zeros(1000); %x-position
y=zeros(1000); %y-position
vx=zeros(1000); %x-velocity
vy=zeros(1000); %y-velocity
for i=1:n
t(i)=i*dt;
vx(i)=vx0+fdragx*dt;
vy(i)=vy0+fdragy*dt;
x(i)=x0+vx(i)*dt;
y(i)=y0+vy(i)*dt;
x0=x(i);
y0=y(i);
vx0=vx(i);
vy0=vy(i);
end
plot(x,y,'g+')