here is a shooting method solution right out of the docs:
sol = First[
NDSolve[{x''[t] + Sin[x[t]] == 0 , x[0] == x[10] == 0}, x, t,
Method -> {"Shooting",
"StartingInitialConditions" -> { x'[0] == 1.666 }}]]
Plot[Evaluate[x[t] /. sol], {t, 0, 10}]
The shooting method is of course iterative, so how to monitor progress (initial condidion vs end condition )? I came up with this sort of hack approach and I wonder if there is a better way:
define a function that always returns zero, but saves what we want as a side effect:
zero[t_?NumericQ, x_, xp_] :=
(If[t == 0, xp0 = xp, If[t == 10, Sow[{xp0,x}]]]; 0)
now add as a term in the equation (no effect on solution since its always 0
):
r = Reap[NDSolve[{x''[t] + Sin[x[t]] == zero[t, x[t], x'[t]] ,
x[0] == x[10] == 0}, x, t,
Method -> {"Shooting",
"StartingInitialConditions" -> { x'[0] == 1.666}}]][[2, 1]];
ListPlot[r, Frame -> True, FrameLabel -> {"x'[0]", "x[10]"}]
is there a better way? I tried working with WhenEvent
with no luck..