[Math] Projectile with air drag using MATLAB

MATLABprojectile motion

Unsure where to ask this question because it involves coding and mathematics.

I am currently using the code

function [p] = dataODE( t, x)

global k g

p = zeros(4,1);
p(1) = x(2);
p(2) = -k*sqrt(x(2)^2 + x(4)^2)* x(2);
p(3) = x(4);
p(4) = -g -k*sqrt(x(2)^2 + x(4)^2)* x(4);

and

global k g

g = 10;
v0 = 150;
theta = pi/4;
m = 1;
k = 0.001;

tspan = [0 16];

IC = [0; v0*cos(theta); 0; v0*sin(theta)];
[t, oput] = ode45(@dataODE, tspan, IC);

x = oput(:,1);
vx = oput(:,2);
y = oput(:,3);
vy = oput(:,4);

figure(1); clf;
plot(x,y)

to plot the path of a projectile with air drag (coefficient k = 0.001).

There are a few points that I am stuck with:
How do I calculate where the projectile lands? (So far I am just estimating by eye-balling the graph).

And how do I then adjust this code to find the optimal angle to achieve the maximum distance?

Any hints are greatly appreciated

Best Answer

If you set the x axis as ground, then the object lands when its position function, y, =0.

The x value at y=0 is the horizontal distance traveled by the object. Run a loop of angles from 0 to 90, and find horizontal distances for those angles. Plot them, and you will see a peak at what should be a specific and intuitive angle.

Related Question