3
$\begingroup$

I am looking at a particle moving in a funny potential, described by the following differential equation. The solution should be just some kind of periodic trajectory, why is there a problem here?

enter image description here

Edit: here is the code:

k = NDSolve[{x'[t]^2 + 1/Cos[x[t]]^2 == 2, x[0] == 0}, 
  x[t], {t, 0, 4}]
$\endgroup$
8
  • $\begingroup$ Please provide your Mathematica code for this interesting problem! $\endgroup$ Aug 11, 2021 at 16:20
  • 2
    $\begingroup$ Assuming x[t] to be real your ode evaluates negative x'[t]^2 for x[t]>= Pi/4 !!! That's why NDSolve stops for x[t]==Pi/4. $\endgroup$ Aug 11, 2021 at 16:52
  • $\begingroup$ Both terms are squared, how can anything become negative? $\endgroup$
    – korni1990
    Aug 11, 2021 at 18:03
  • $\begingroup$ @korni1990 It evaluates to false, because 1/Cos[x[t]]^2 will get larger than 2 and the other term is squared. $\endgroup$
    – Coolwater
    Aug 11, 2021 at 18:33
  • $\begingroup$ I see, thanks! But why is x[t] not simply decreasing after reaching the 'turning point' as it should? Is this not possible with NDSolve? $\endgroup$
    – korni1990
    Aug 11, 2021 at 18:36

2 Answers 2

6
$\begingroup$

Your differential equation has a singularity at $x(t) = \pi/2 \approx 1.54$, and that is why the integrator has troubles approaching that point. To solve this, use:

  1. Initial value for the first derivative

$$x(0) = 0 \implies x'(0) = \pm 1$$

  1. Method -> {"EquationSimplification" -> "Residual"}
k = NDSolve[{x'[t]^2 + 1/Cos[x[t]]^2 == 2, x'[0] == 1
   }, x[t], {t, 0, 10}, 
  Method -> {"EquationSimplification" -> "Residual"}] 
Plot[Evaluate[x[t]] /. k, {t, 0, 10}]

Mathematica graphics

$\endgroup$
4
  • $\begingroup$ Cool thanks, that does the job indeed. $\endgroup$
    – korni1990
    Aug 11, 2021 at 19:11
  • $\begingroup$ Your code in "12.3.1 for Mac OS X x86 (64-bit) (June 19, 2021)" gives an error: "NDSolve::ndcf: Repeated convergence test failure at t == 7.7854479164218`; unable to continue." Are you using a different version, or did you do something not shown in the code? $\endgroup$
    – Michael E2
    Aug 11, 2021 at 22:50
  • $\begingroup$ @MichaelE2 No, I run exactly the same code in 12.3.0 for Microsoft Windows (64-bit) (May 10, 2021) without errors. $\endgroup$
    – Domen
    Aug 12, 2021 at 11:47
  • $\begingroup$ In my case, NDSolve is probably stepping slightly below -Pi/4, but I wonder what changed (assuming it’s version-related, not OS/CPU related). $\endgroup$
    – Michael E2
    Aug 12, 2021 at 14:23
2
$\begingroup$

Your initial condition implies x[0] == 0 && x'[0] == 1.
Using the corresponding 2nd order equation works well:

eq = D[x'[t]^2 + 1/Cos[x[t]]^2 == 2, t];
sols = x[t] /. NDSolve[{eq, x[0] == 0, x'[0] == 1}, x[t], {t, 0, 5}];
Plot[sols, {t, 0, 5}, PlotRange -> All]

$\endgroup$

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.