close all;
clear;
clc;
m = 0.145;
D = 0.0738;
A = (pi/4)*D^2;
Cd = 0.35;
ti = 0;
vi = 49;
xi = 0;
yi = 0;
g = 9.81;
p0 = 1.22;
y0 = 8300;
dt = 0.001;
i = 1;
dtheta = 5;
theta = 30;
for theta = 30:5:60
while ti < 5
vxi = 49*cosd(theta);
vyi = 49*sind(theta);
dxdt = vxi;
dydt = vyi;
py = p0*exp(-yi/y0);
dvxdt = ((-0.5*Cd*A.*py)/m).*dxdt.^2;
dvydt = (-g - ((0.5*Cd*A.*py)/m).*dydt.^2);
vxf = vxi + dvxdt*dt;
vyf = vyi + dvydt*dt;
xf = xi + dxdt*dt - (1/2)*dvxdt*(dt)^2;
yf = yi + dydt*dt - (1/2)*dvydt*(dt)^2;
tf = ti + dt;
ti = tf;
vxi = vxf;
vyi = vyf;
xi = xf;
yi = yf;
T(i) = ti;
X(i) = xi;
Y(i) = yi;
i = i + 1;
end
end
Ok!
So for my computational physics course, we are tasked with plotting the trajectory of a homerun ball (taking into account the air drag) for different angles. Those angles range from 30 to 60 degrees in increments of 5 degrees.
Basically what I want to do is loop through that entire while loop for 30 degrees, then plot that, then loop through it again at 35 degrees, and then plot that. I want to continue that until 60 degrees. I'd like all of the plots to be on one graph
What I've tried:
I tried an if statement that just said:
hold on;
if theta == 30
plot(X,Y)
elseif theta == 35
plot(X,Y)
elseif theta == 40
plot(x,Y)
end
This didn't work. I won't lie, I'm not good at coding like at all so I still hardly understand how this stuff works. Any help would be greatly appreciated.
SIDE NOTE: I suspect the physics isn't correct. I'm not asking this community to help with that, buuuuut if you have any insight, that would also be appreciated