1
$\begingroup$

I want to simulate a projectile motion under the effect of air resistance by using Append in a For loop, but there appeared to be no changes in the two lists I defined for storing horizontal and vertical coordinates.

Here are my codes for updating the two lists:

d = 1;(* d stands for drag coefficient *)
m = 1;(* m stands for mass *)
v = 3;(* v stands for muzzle velocity *)
k = 10; (* k determines accuracy *)
theta = 35.5 Degree; (* initial angle *)

For[
ax = -d/m*v*v*Cos[theta];(* ax stands for initial horizontal acceleration *)
ay = -9.8 - d/m*v*v*Sin[theta];(* ay stands for initial vertical acceleration *)
vx = v*Cos[theta];(* vx stands for initial horizontal velocity *)
vy = v*Sin[theta];(* vy stands for initial vertical velocity *)
x = 0;(* x stands for initial horizontal position *)
y = 0;(* y stands for initial height *)
xlist = {0};
ylist = {0};
i = 1,

i < 10 + 1,(* desired time in seconds is determined by i[max]*k *)

i++,

ax = -d/m*(vx^2 + vy^2)^0.5*vx;
ay = -d/m*(vx^2 + vy^2)^0.5*vy;
vx = vx + ax*(i/k);
vy = vy + ay*(i/k);
x = x + vx*(i/k) + 1/2*ax*(i/k)^2;
y = y + vy*(i/k) + 1/2*ay*(i/k)^2;
Append[xlist, x];
Append[ylist, y]
]

When I tried to print xlist and ylist, I got: {0} {0}

Any help appreciated.

$\endgroup$

Browse other questions tagged or ask your own question.