1
$\begingroup$

Here are some basic equations

Vn = -Mn/Sqrt[R^2 + z^2 + cn^2]; Vd = -Md/Sqrt[b^2 + R^2 + (a + Sqrt[h^2 + z^2])^2]; Vh = υ0^2/2 Log[R^2 + β*z^2 + ch^2]; Vt = Vn + Vd + Vh; V = Vt + Lz^2/(2*R^2); Vt = V /. {R -> R[t], z -> z[t]}; 

the values of the parameters

Mn = 250; cn = 0.25; Md = 7000; b = 6; a = 3; h = 0.2; υ0 = 20; β = 1.5; ch = 8.5; Lz = 10; En = 600; 

the forces along R and z coordinates

FR = -D[V, R]; Fz = -D[V, z]; FRt = FR /. {R -> R[t], z -> z[t]}; Fzt = Fz /. {R -> R[t], z -> z[t]}; 

the system of the differential equations

DifferentialEquations[R0_, z0_, pR0_, pz0_] := Module[{Deq1, Deq2, Deq3, Deq4}, Deq1 = R'[t] == pR[t]; Deq2 = z'[t] == pz[t]; Deq3 = pR'[t] == FRt; Deq4 = pz'[t] == Fzt; {Deq1, Deq2, Deq3, Deq4, R[0] == R0, z[0] == z0, pR[0] == pR0, pz[0] == pR0} ] 

the initial conditions

R0 = 5; z0 = 0; pR0 = 0; pz0 = Sqrt[2*(En - V) - pR0^2] /. {R -> R0, z -> z0} tmax = 500; 

and the integration loop

sdeq = DifferentialEquations[R0, z0, pR0, pz0]; data0 = {}; sol = NDSolve[sdeq, {R[t], z[t], pR[t], pz[t]}, {t, 0, tmax}, MaxSteps -> Infinity, WorkingPrecision -> MachinePrecision, PrecisionGoal -> 12, AccuracyGoal -> 12, Method -> {"EventLocator", "Event" -> z[t], "Direction" -> -1, "EventAction" :> AppendTo[data0, {{R[t], pR[t]}, {R[t], -pR[t]}}], Method -> "Adams"}]; 

Mathematica does not report any mistakes the integration loop. However no output is produced (empty data0 list) the program consumes all the available memory until it crashes.

Any ideas about what cause this? Also any suggestions for code improvements are more than welcome!

$\endgroup$
4
  • $\begingroup$ I copied and ran your code, which took only several seconds. R[t] and pR[t] are rapidly oscillating functions, while z[t] and pz[t] appear to be zero. Note that Fzt is proportional to z, so if z starts at zero it would appear to stay at zero. $\endgroup$ Commented Jan 19, 2015 at 18:44
  • $\begingroup$ D0 you mean that data0 is not empty? If not, can you please make a quick ListPlot of the elements of the list? $\endgroup$ Commented Jan 19, 2015 at 19:53
  • $\begingroup$ No, data0 is empty, as it would be for z[t] identically zero. $\endgroup$ Commented Jan 19, 2015 at 19:54
  • $\begingroup$ @Vaggelis_Z: Your code is ok except for one typo, a semicolon before tmax. The commands should read: R0 = 5; z0 = 0; pR0 = 0; pz0 = Sqrt[2*(En - V) - pR0^2] /. {R -> R0, z -> z0} ; tmax = 500; $\endgroup$ Commented Jan 19, 2015 at 20:19

1 Answer 1

6
$\begingroup$

The code as displayed in the Question runs fine for me using Mathematica 10.0.2.0 under Windows 8.1 (64 bit). However, as I noted in a Comment, z0 = 0 causes z[t] to remain zero. Arbitrarily, I set z0 = 0.1 (and also tmax = 5), which produced

z[t]

with data0

 {{{3.02779, -18.7347}, {3.02779, 18.7347}}, {{4.02275, 13.1626}, {4.02275, -13.1626}}, {{1.7836, -24.1793}, {1.7836, 24.1793}}, {{4.16014, 12.1853}, {4.16014, -12.1853}}, {{1.52373, -25.3168}, {1.52373, 25.3168}}, {{4.2339, 11.586}, {4.2339, -11.586}}, {1.21978, -26.7392}, {1.21978, 26.7392}}, {{4.35913, 10.4842}, {4.35913, -10.4842}}, {{0.67748, -29.6552}, {0.67748, 29.6552}}, {{4.57951, 8.54321}, {4.57951, -8.54321}}, {{0.582273, -30.0941}, {0.582273, 30.0941}}, {{4.68988, 7.3793}, {4.68988, -7.3793}}, {{0.499859, -30.1679}, {0.499859, 30.1679}}, {{4.85037, 5.13218}, {4.85037, -5.13218}}, {{0.236406, -9.23721}, {0.236406, 9.23721}}} 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.