Using NDSolve to find particle trajectory
The main problem is that your pos
is not seen as a 3D vector.
The cross product is therefore interpreted as a scalar:
q*Cross[D[pos[t], t], b]
when adding this to the vector q.e this 'scalar' term is added to each of the vector components:
q*e + q*Cross[D[pos[t], t], b]
This won't work, instead do:
b = {1, 0, 0};
e = {0, 0, 1};
q = 1;
m = 1;
Define pos
as a 3D vector. Also take more time than a single second:
ClearAll[pos]
pos[t_] = {px[t], py[t], pz[t]};
sol = NDSolve[
{
q*e + q*Cross[D[pos[t], t], b] == m D[pos[t], {t, 2}],
pos[0] == {0, 0, 0},
(D[pos[t], t] /. t -> 0) == {0, 0, 0}
}, pos[t], {t, 0, 20}]
ParametricPlot3D[Evaluate[pos[t] /. sol], {t, 0, 20}]
Alternative method:
b = {1, 0, 0};
e = {0, 0, 1};
q = 1;
m = 1;
sol = NDSolve[{e + Cross[pos'[t], b] == m/q pos''[t],
pos[0] == {0, 0, 0}, pos'[0] == {0, 0, 0}}, pos, {t, 0, 10},
Method -> {"EquationSimplification" -> "Residual"}];
ParametricPlot3D[pos[t] /. sol, {t, 0, 10}, PlotRange -> All]
Another alternative is to package your constant vector parameters as DiscreteVariables
. In the OP's case, it necessary only to chnage e
since b
occurs inside Cross
, which will not evaluate until all its arguments are vectors. Note that in the equation we changed e
to e[t]
and set its value with e[0] == {0, 0, 1}
.
b = {1, 0, 0};
(*e={0,0,1};*)
q = 1;
m = 1;
sol = NDSolve[{q*e[t] + q*Cross[D[pos[t], t], b] == m D[pos[t], {t, 2}],
pos[0] == {0, 0, 0}, (D[pos[t], t] /. t -> 0) == {0, 0, 0},
e[0] == {0, 0, 1}}, pos, {t, 0, 10}, DiscreteVariables -> {e}];
ParametricPlot3D[pos[t] /. sol, {t, 0, 10}, PlotRange -> All]