I need to calculate the following function with replacement in recurrence
f[x0_, y0_]:= (s1 + s2)/t1 /. {s1 ->
NDSolveValue[{x''[t] + x[t] == 0., y''[t] + x[t]^2 y[t] == 0.,
x[0.] == x0, x'[0.] == 0., y[0.] == y0, y'[0.] == 0.},
y, {t, 0, t1}][t1], s2 -> NDSolveValue[{x''[t] + x[t] == 0, y''[t] + x[t]^2 y[t] == 0.,
x[0.] == x0, x'[0.] == 0., y[0.] == y0, y'[0.] == 1.},
y, {t, 0, t1}][t1]} /. {t1 -> Take[Reap[
NDSolve[{x''[t] + x[t] == 0., x[0.] == x0, x'[0.] == 0.,
WhenEvent[x'[t] > 0., {Sow[t], "StopIntegration"}]},
x, {t, 0., 100.},
MaxStepSize -> 0.001]], {2, -1}][[1]][[1]][[1]]}
But I meets an error says "NDSolveValue: Endpoint t1 in {t, 0., t1} is not a real number".
The key expression is
NDSolveValue[{x''[t] + x[t] == 0, y''[t] + x[t]^2 y[t] == 0.,
x[0.] == 1., x'[0.] == 0., y[0.] == 1., y'[0.] == 0.},
y, {t, 0, Re[t1]}][Re[t1]] /. {t1 -> Take[Reap[
NDSolve[{x''[t] + x[t] == 0, x[0.] == 1., x'[0.] == 0.,
WhenEvent[x'[t] > 0., {Sow[t], "StopIntegration"}]},
x, {t, 0., 100.},
MaxStepSize -> 0.001]], {2, -1}][[1]][[1]][[1]]}
which comes the error. How can I solve this problem?
s1
with a symbolic endpointt1
and then afterwards replacingt1
with a calculated value. To avoid the warning, computet1
first. $\endgroup$