Sorry if the question seems trivial, but I am new to physical simulations in Mathematica. I have a numerical estimation of an electric potential $V(x)$ in 3D, to be more precise I have a matrix containing $[x , y, z , V(x, y, z)]$ in a cubic domain, so the potential in not an analytic function . Is there a method, using Mathematica, to solve numerically the equation of motion for a charged particle in the potential? Essentially I would like to solve $\frac{d^2}{dt^2} \textbf{x}(t) = e \nabla V (\textbf{x}(t)) $ with certain initial conditions.

  • $\begingroup$ Is your discrete function a sampling or approximation of an underlying continuous function? If so, use FindFit to get the 3D potential and then Solve to calculate the particle trajectories. (If instead your potential is constant within a cubelet, then the derivatives vanish and if your particle ever sits within a cubelet, it will remain in that cubelet forever, even though regions with lower potential may exist.) $\endgroup$ Feb 20 '15 at 19:20
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$
    – bbgodfrey
    Feb 20 '15 at 19:27
  • $\begingroup$ No, the discrete function is the result of a finite element simulation. An analytic model for the potential doesn't seem to be available. $\endgroup$
    – user47224
    Feb 20 '15 at 19:28
  • $\begingroup$ Please take a look at Interpolation[] $\endgroup$ Feb 20 '15 at 19:42

For example:

(*Your matrix*)
max = 2 Pi; 
pot = Table[{{x, y, z}, Sin@x y z } // N, {x, 0, max, max/40}, {y, 0, max,  max/20}, 
                                          {z, 0, max, max/20}];
v = Interpolation@Flatten[pot, 2];
dx[x_, y_, z_] := D[v[r, y, z], r] /. r -> x
dy[x_, y_, z_] := D[v[x, r, z], r] /. r -> y
dz[x_, y_, z_] := D[v[x, y, r], r] /. r -> z

sol = NDSolve[{
    x''[t] == dx[x[t], y[t], z[t]], x[0] == 1, x'[0] == 1,
    y''[t] == dy[x[t], y[t], z[t]], y[0] == 1, y'[0] == -1,
    z''[t] == dz[x[t], y[t], z[t]], z[0] == 1, z'[0] == 0
   {x[t], y[t], z[t]}, {t, 0, 2}];

ParametricPlot3D[{x[t], y[t], z[t]} /. sol, {t, 0, 2}]

Mathematica graphics

  • $\begingroup$ Your solution seems to work correctly. The only issue is related to the mesh of the sampling that in my case is not uniform and gives a warning. The solution is computed though. $\endgroup$
    – user47224
    Feb 21 '15 at 17:47
  • $\begingroup$ @user47224 If you search this site you'll find a couple of questions about interpolating in non-uniform grids. Thanks for the accept! $\endgroup$ Feb 21 '15 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.