An alternative, perhaps simpler, approach makes use of the fact that the Hamiltonian is a constant of the motion here. This can be validated by constructing the time-derivative of the Hamiltonian.
eqs = {q'[t] == p[t] (p[t]^2 + q[t]^2), p'[t] == -q[t] (p[t]^2 + q[t]^2)};
q[t] eqs[[1, 2]] + p[t] eqs[[2, 2]]
(* 0 *)
Setting the Hamiltonian equal to ω^2
then yields
eqs1 = eqs /. (p[t]^2 + q[t]^2) -> ω
(* {Derivative[1][q][t] == ω p[t], Derivative[1][p][t] == -ω q[t]} *)
which DSolve
handles without difficulty.
s = Collect[DSolve[{eqs1, q[0] == -1, q[Pi] == 1}, {p[t], q[t]}, t],
{Sin[t ω], Cos[t ω]}, Simplify] // Flatten
(* {p[t] -> Cos[t ω] Cot[(π ω)/2] + Sin[t ω], q[t] -> -Cos[t ω] + Cot[(π ω)/2] Sin[t ω]} *)
Edit: Finally, ω
is determined by p[t]^2 + q[t]^2 == ω
Total[#^2 & /@ ({p[t], q[t]} /. s)] // FullSimplify
(* Csc[(π ω)/2]^2 *)
So, the eigenvalue equation is
ω Sin[(π ω)/2]^2 - 1 == 0
Plotting this function indicates the locations of the roots,
Plot[ω Sin[(π ω)/2]^2 - 1, {ω, 0, 12}]
And the roots themselves are given by
freq = ω /. NSolve[ω Sin[(π ω)/2]^2 - 1 == 0 && .4 < ω < 20, ω]
(* {1., 1.33333, 2.44206, 3.64927, 4.31956, 5.72552, 6.26172, 7.76635,
8.22672, 9.79293, 10.2027, 11.812, 12.185, 13.8267, 14.1712, 15.8383,
16.16, 17.8479, 18.1508, 19.8559} *)
p1 = Plot[Evaluate[q[t] /. s /. ω -> freq[[1 ;; 6]]], {t, 0, Pi}]
Addendum
The derivation above misses some solutions. Apply DSolve
to eqs1
without the boundary conditions.
{q[t], p[t]} /. DSolve[{eqs1}, {p[t], q[t]}, t] // First
(* {C[2] Cos[t ω] + C[1] Sin[t ω], C[1] Cos[t ω] - C[2] Sin[t ω]} *)
The first boundary condition yields
% /. t -> 0
(* {C[2], C[1]} *)
Consequently, C[2] == -1
and ω == 1 + C[1]^2
. The second boundary condition then yields
Reduce[(%%[[1]] /. {C[2] -> -1, t -> Pi}) == 1, C[1]] // FullSimplify
(* (Sin[π ω] == 0 && Cos[π ω] == -1) || (Sin[π ω] != 0 && C[1] == Cot[(π ω)/2]) *)
The second result is the one obtained earlier. The first, however, is new. It is satisfied by ω
any odd integer. Corresponding solutions are, for instance,
p2 = Plot[Evaluate[{-Cos[t ω] + Sqrt[ω - 1] Sin[t ω], -Cos[t ω] - Sqrt[ω - 1] Sin[t ω]} /.
ω -> {3, 5}], {t, 0, Pi}, PlotStyle -> Dashed]
Between them, plots p1
and p2
depict all solutions for ω < 6
.
Show[p1, p2]
Incidentally, one might have expected DSolve
with the boundary conditions and
SetOptions[Solve, Method -> Reduce];
to return both sets of solutions but it does not.