0

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+')
prgao
  • 1,767
  • 14
  • 16
Mel Carlin
  • 1
  • 1
  • 1
  • 1
    Besides forgetting gravity like @prgao said, the drag force should update inside the loop. Right now the drag force is constant in time. – kalhartt Oct 09 '13 at 00:35
  • I've updated the for loop to this http://imgur.com/ikLboeU but it still isn't fully modelling the gravity, ideas? – Mel Carlin Oct 09 '13 at 00:51

2 Answers2

1

it doesn't look like you are modeling the downward acceleration of g force for your y velocity

prgao
  • 1,767
  • 14
  • 16
0

Looks like there were three issues.

First you missed gravity in updating vy. Fixed

Second drag force was not updating with the velocity. Fixed

Thirdly, your calculating the new position/velocities using the initial values and not the previous ones. In the loop try changing these lines. You might have to update your for loop to go from 2:n if matlab indexes at 1.

vx(i)=vx(i-1)+fdragx*dt;
vy(i)=vy(i-1)+(-g+fdragy)*dt;
x(i)=x(i-1)+vx(i)*dt;
y(i)=y(i-1)+vy(i)*dt;

Edit: Didnt see the update of the initial conditions, disregard the third comment.

kalhartt
  • 3,999
  • 20
  • 25