How to find period of the interpolating function

Code is:

m[t_] := {mx[t], my[t], mz[t]}

γ = 28;

h = 6.62*10^-34;

e = 1.6*10^-19;

Subscript[μ, 0] = 1.25*10^-6;

Subscript[μM, 0] = 800*10^-3;

Subscript[M, 0] = 0.64*10^6;

Subscript[r, 0] = 100*10^-9;

Subscript[l, 0] = 3*10^-9;

Subscript[I, dc] = 1*10^-3;

Subscript[B, dc] = 200*10^-3;

Subscript[α, G] = 0.01;

p = {0, 0, 1};

σ =(γ*h/2*e)*1/(Subscript[M, 0]*Pi*(Subscript[r, 0])^2)*Subscript[l, 0];

Subscript[B, eff] = {Subscript[B, dc], 0, 0}-Subscript[μM, 0]*(m[t]*p);

system1 ={D[m[t], t] ==γ*(Cross[Subscript[B, eff], m[t]]) + Subscript[α, G]*(Cross[m[t], D[m[t], t]]) +σ*Subscript[I, dc]*(Cross[m[t], Cross[m[t], p]]),(m[t] /. t -> 0) == {0, 1, 0}};

s1 = NDSolve[system1, m[t], {t, 0, 50}]

Plot[Evaluate[{mx[t], my[t], mz[t]} /. s1], {t, 0, 50},AxesLabel -> {t, m}]

Plot[Evaluate[mx[t] /. s1], {t, 0, 50}, AxesLabel -> {t, mx}]


I need for mx (t) calculate how changes the magnetization of the oscillation frequency f 0 during the time of 50 ns and plot a graph f (t).

• You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. You may also find this meta Q&A helpful Sep 25 '16 at 18:36
• Related (see WhenEvent): (40122), (106006), (127095) Sep 25 '16 at 18:45

We can sow the minima of each coordinate and look at the intervals near the end of integration.

{s1, {{x0}, {y0}, {z0}}} = Reap[
NDSolve[{system1,
WhenEvent[mx'[t] > 0, Sow[t, "x"]],   (* minima of x *)
WhenEvent[my'[t] > 0, Sow[t, "z"]],   (* minima of y *)
WhenEvent[mz'[t] > 0, Sow[t, "y"]]},  (* minima of z *)
m[t], {t, 0, 50}],
{"x", "y", "z"}];


Here are the approximate periods:

Table[Mean@ Differences@ min[[-Round[Length@min/4] ;;]], {min, {x0, y0, z0}}]
(*  {0.25092, 0.501841, 0.501841}  *)


We can see that mx has twice the frequency of the other components:

Plot[Evaluate[{2000 (mx[t] - 1), my[t], mz[t]} /. s1], {t, 45, 50},
AxesLabel -> {t, m}]


• Hi Michael, what does the second box of code exactly do (why do you only start after a 4th of the data points)? And shouldn't the 'zeros' be replaced with the current list, i.e. 'max'? Nov 10 '16 at 17:35
• @fber Thanks for pointing out the typo. One should need only take the difference of last two minima, once the "transient" part of the solution has settled down. Using the Mean[] of the tail (last 1/4) of the minima just averages out noise that is in the minima. Strictly speaking the solution seems only to be approximately periodic, if the drift (blue) and diminishing amplitudes (yellow, green) can be ignored. Nov 12 '16 at 2:10
• Thanks for correcting and the explanation. Now it's clear to me. (Also switching the variable name from 'max' to 'min' helped.) Nov 14 '16 at 23:31