The goal is basically to create a plot of both altitude and velocity vs time . Given equations are: d^2y/dt^2=-g-b*v P(y)=P(0)*e^(-ky)
This is that I've attempted so far:
k = 1.256*10^-4;
b = 0.3266;
g = 9.8;
e = 2.71828;
inc = 0.1;
t[0] = 0;
v[0] = 0;
y[0] = 0;
P[0] = 17696;
P[y] = P[0]*e^(-k*y[t]);
y[t] = -g*y[t]*-b*y[t]*0.5*y^2;
v[t] = -g*v[t]*-b*v[t]*y[t];
a[t] = -g*-b*v[t];
i = 0;
While[
y[i] > 0,
P[i + 1] = P[0]*e^(-k*y[i]);
t[i + 1] = t[i] + inc;
y[i + 1] = v[i]*inc + y[i];
v[i + 1] = a[i]*inc + v[i];
a[i + 1] = -g*-b*v[i];
i++
];
ptsvt = Table[{t[j], v[j]}, {j, 0, i}];
ptspt = Table[{t[j], P[j]}, {j, 0, i}];
ListLinePlot[ptsvt]
ListLinePlot[ptspt]
I'm pretty sure the main mistake is in the definition of y[t] and v[t]. I've tried several different equations and nothing seems to work. I'm not even sure if defining y[t] and v[t] is the right way to do it but I can't think of any other way. Any help would be greatly appreciated!
y[0]=0
andi=0
and thenWhile[y[i]>0...
So think a minute. What does that mean happens with yourWhile
loop? Think carefully about those three things. Maybe you could put aPrint
before and another one inside yourWhile
and another one after it is done to show you what is happening at each step. $\endgroup$a[0] = -g - b*v[0];
anda[i + 1] = -g - b*v[i];
(i.g., gravityg
and magnetic accelertion b*v[i] of charged particle? Otherwise, acceleration, velocity, and position remain0
all the time. $\endgroup$