Message Boards Message Boards

Thoroughly confused by NDSolve

Posted 10 years ago
Hi all, I am new to using Mathematica and slowly getting the hang of things but I still find the approach confusing at times.

So having read up on the tutorials for using NDSolve, and testing it out on a few toy equations that I can solve by hand, I tried setting it up to solve a real problem.  (Electron motion in a laser field).  NDSolve appears to run and provides me with a "solution" of InterpolatingFunctions but when I come to evaluate them they do not evaluate, (see code below).  What am I doing wrong here?
 c0 = 1;
 \[Omega] = 1;
 vg = 1;
 vp = 1;
 \[Sigma] = 1;
 \[Rho] = 1;
 Subscript[A, 0] = 1;
 q = 1;
 m = 1;
y = 0;
A[x_, z_, t_] :=
  Subscript[A, 0]
    Exp[-(z - vg t)/\[Sigma]^2] Exp[(-x^2 - y^2)/\[Rho]^2] Exp[
    I \[Omega] (z/vg - t)];
s = NDSolve[{D[x[t], {t, 2}] == q/m D[A[x[t], z[t], t], t],
   D[z[t], {t, 2}] == -(q/m) D[x[t], t] A[x[t], z[t], t], x'[0] == 0,
   z'[0] == 0, x[0] == 0, z[0] == 0}, {x[t], z[t]}, {t, 0, 10}]
Plot[Evaluate[{x[t], z[t]} /. s], {t, 0, 10}, PlotRange -> All]
Evaluate[{x[1], z[1]} /. s]

This simply refuses to evaulate and gives me an empty graph and
{{x[1], z[1]}}

What am I missing?
POSTED BY: Phil Tooley
If you change {x, z} to {x,t} in NDSolve, then you'll get better results.  However, your functions are 0 everywhere, which you can see by setting the AxesOrigin of the plot to {0,-1}
 c0 = 1;
 \[Omega] = 1;
 vg = 1;
 vp = 1;
 \[Sigma] = 1;
 \[Rho] = 1;
 Subscript[A, 0] = 1;
 q = 1;
 m = 1;
y = 0;
A[x_, z_, t_] := Subscript[A, 0]
Exp[-(z - vg t)/\[Sigma]^2] Exp[(-x^2 - y^2)/\[Rho]^2] Exp[
   I \[Omega] (z/vg - t)];
s = NDSolve[{D[x[t], {t, 2}] == q/m D[A[x[t], z[t], t], t],
    D[z[t], {t, 2}] == -(q/m) D[x[t], t] A[x[t], z[t], t], x'[0] == 0,
     z'[0] == 0, x[0] == 0, z[0] == 0}, {x, z}, {t, 0, 10}];
{x[1], z[1]} /. s
{{0., 0.}}
POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract