# Initial time as parameter in ParametricNDSolve

I need a help with the function ParametricNDSolve. My goal is solve the equation \begin{array} &&\dot{x}(t) = y(t) \\ &\dot{y}(t) = x(t)-1-\varepsilon Cos(\omega t) \\ &x(t_0) = x_0\\ &y(t_0) = y_0 \end{array} where, $x_0,y_0,t_0$ and $\varepsilon$ are parametres that i wish to adjust. The option i chose was the function ParametricNDSolve. So, to solve that equation the function became

sol = ParametricNDSolve[{x'[t] == y[t],
y'[t] == x[t] - 1 - \[Epsilon] Cos[5 t], x[t0] == x0 ,
y[t0] == y0}, {x, y}, {t, 0, 10}, {t0, x0, y0, \[Epsilon]}]


Until here no problem. But, when I try to plot

Plot[Evaluate[Table[y[0, 0, y0, 0][t] /. sol, {y0, -1, 1, .1}]], {t,0, 1}, PlotRange -> All]


Mathematica returns this mensagem

ParametricNDSolve::ndsv: Cannot find starting value for the variable x. >>


I know that the problem is in parameter $t_0$, because when I run this functions with $t_0 = 0$ no problem apperars.

Someone has some ideia what is going on? Some sugestion to solve this problem?

Sorry about my english.

• You may change the t0 dependency by a phase in the Cosine – Dr. belisarius Mar 7 '15 at 16:45

## 2 Answers

Apparently, ParametricNDSolve cannot handle x[t0] or y[t0] when t0 is a parameter. A work-around is to shift time to begin at t0, in which case the code becomes,

sol = ParametricNDSolve[{x'[t] == y[t],
y'[t] == x[t] - 1 - ϵ Cos[5 (t + t0)], x[0] == x0,
y[0] == y0}, {x, y}, {t, -t0, -t0 + 10}, {t0, x0, y0, ϵ}]


which works fine. This does seem like a Mathematica shortcoming, however.

• I think in general the usage would be y[t0, x0, y0, ϵ][t - y0] /. sol, and one would want to integrate over {t, -t0, -t0 + 10}. – Michael E2 Mar 8 '15 at 3:23
• @MichaelE2 I have made the correction. Thank you. – bbgodfrey Mar 8 '15 at 13:17
• You're welcome. :) (+1) -- oops, I meant y[t0, x0, y0, ϵ][t - t0] /. sol. [Typo with y0 in place of t0.] – Michael E2 Mar 8 '15 at 13:23

Given that ParametricNDSolve does not handle this case, one can revert to the old way. Uncomment the memoization if desired; it will speed things up if sol is called multiple times with the same parameters.

Clear[sol];
sol[t0_, x0_, y0_, ϵ_] :=
(*sol[t0, x0, y0, ϵ] =*)
NDSolve[{x'[t] == y[t], y'[t] == x[t] - 1 - ϵ Cos[5 t],
x[t0] == x0, y[t0] == y0}, {x, y}, {t, 0, 10}]


Here's a different plot to show that the dependence on t and t0 is as desired:

Plot[Evaluate[Table[y[t] /. sol[t0, 0, 1, 0], {t0, -1, 1, .2}]],
{t, 0, 1}, PlotRange -> All, GridLines -> {None, {1}}]