# Projectile motion with air resistance using Euler's method

1. Oct 7, 2011

### zheng89120

1. The problem statement, all variables and given/known data

Calculate the trajectory of our canon shell including both air drag and reduced air density at high altitudes so that you can reproduce the results in Figure 2.5. Perform your calculation for different firing angles and determine the value of the angle that gives the maximum range. //what are the speed and angle of the canon ball? using 700 m/s and 30,35,40,45,50,55 degrees

2. Relevant equations

C language and basic Computational physics

3. The attempt at a solution

/* This is Problem 2_9 of 313's Problem set 2, by Zach Zheng */

#include <stdio.h>
#include <math.h>

main()
{
/* Declare variables */
double x; //Eulers ball position in x
double y; //Eulers ball position in y
double x_o; //Initial ball position in x
double y_o; //Initial ball position in y
double v; //Eulers ball speed
double v_x; //Eulers ball speed in x
double v_y; //Eulers ball speed in y
double v_x_o; //Initial ball speed in x
double v_y_o; //Initial ball speed in y
double p; //Air density
double p_o; //Initial air density
double m; //Ball mass
double g; //gravity constant
double theta; //Initial launch angle
double C; //Drag constant
double A; //Ball area
double dt,tmax,t; // Timestep, Maximum time,Current time

/* Set initial values for variables */
v = 700.0; //set initial speed
theta = M_PI/6.0; //set initial angle to 30 degrees
v_x = v_x_o; //set initial speed variable in x
v_x_o = v*cos(theta); //set initial speed constant in x
v_y = v_y_o; //set initial speed variable in y
v_y_o = v*sin(theta); //set initial speed constant in y
x = 0.0; //initial position
y = 0.0; //initial position
y_o = 10000.0; //initial sea height
m = 1.0; //set ball mass
p = 1.4; //density of air
g = 9.8; //gravity constant
C = 1.0; //set drag constant
A = 0.01; //set ball area
t = 0.0; //set initial time
dt = 0.5; //set time steps
tmax = 50.0; //maximum time

/* Now go through the steps until tmax is exceeded */
while (t < tmax )
{
//no exact solution

printf("%lf\t%lf\t%lf\n", t, x, y); //print statement

v = sqrt(v_x*v_x + v_y*v_y); //total speed

v_x = v_x - exp(-y/y_o)*(1.0/(2.0*m))*C*p*A*fabs(v_x)*v_x*dt; //Euler's solution in x

v_y = v_y - g*dt - exp(-y/y_o)*(1.0/(2.0*m))*C*p*A*fabs(v_y)*v_y*dt; //Euler's solution in y

x = x + v_x*dt; //Position in x as function of speed

y = y + v_y*dt; //Position in y as function of speed

t = t + dt; //time steps
}
}

Last edited: Oct 7, 2011