; solve ; s'' = s-s^3 -s'^2 ; by leapfrog method (properly ordered Euler method applied to ; desynchronized s & v variables; we skip de-synch because v=0 ; at the beginning, which would not change s in the first half-step) s = 1d0 + 0.01d0 v = 0d0 dt = 1d-5 for i=1L, 5000000L do begin ; 1L is long integer type (4 bytes) v_prev = v f = s*(1-s*s) -1000*v^3 ; cases: v^0, v^2, v^4, v^1, v^3 v = v + dt*f s = s + dt*v if(v*v_prev LT 0d0 AND s GT 1d0) then print,i*dt,s,v endfor end ; this script misleadingly looks like Euler method (1st order ; in time) but in reality has accuracy of 2nd order (leapfrog method). ; ; solutions of this nonlinear oscillator equation are oscillating around ; s = 1. program catches and prints at the times when v changes sign, ; that is at the turning points of s(t). ; ; we ran this script five times with different v-dependent term, ; as commented above and observed that for all even powers of velocity ; the fixed point is a circle (amplitude of small oscillatins is ; strictly constant), and that all odd powers result in the loss ; of amplitude of oscillations ; An elegant explanation of the reason for this was given in the ; lecture: the equations are time-reversible if the power is even. ; Reversible systems necessarily have closed trajectories around ; circle fixed points. ;