# Defining variable start position with ParametricNDSolve

I would like to have a variable start point for my initial conditions in ParametricNDSolve. I was hoping ideally this would look like the following (with a random DE used for the example).

soln = ParametricNDSolve[{v''[x] == 10, v'[a] == 1, v[a] == 1},
v, {x, a, 10}, {a}]

vsoln = v /. soln

vsoln[1]


However, this gives the following error:

My expectation is that this is caused by Mathematica not evaluating the given value of a first and so the initial values for the variable are not defined in a way that it can access. Any suggestions here would be greatly appreciated. I'm not nessasarily tied to using ParametricNDSolve but I would like to avoid having to do a change of variable to set v[a] $$\to$$ v*[0], where v* is some shifted function.

## Original Solution

One possible solution is to change ParametricNDSolve to NDSolve but hold the evaluation of the equation. Then later when you're ready and know the desired value of a make the appropriate substitution for a and release the evaluation:

soln = Hold[
NDSolve[{v''[x] == 10, v'[a] == 1, v[a] == 1}, v, {x, a, 10}]]

vsoln[aa_] :=  v /. First[ReleaseHold[ReplaceAll[soln,  a -> aa]]]

vsoln[1]

Plot[vsoln[1][t], {t, 1., 10.}]


## A Second Method

A very similar alternative method that I think is more intuitive is to instead of holding include a condition to not evaluate unless a numerical value is given:

soln[a_?NumericQ] :=
NDSolve[{v''[x] == 10, v'[a] == 1, v[a] == 1}, v, {x, a, 10}]

vsoln[a_] := v /. First[soln[a]]

vsoln[1]
Plot[vsoln[1][t], {t, 1, 10}]


• Now, I'm actually quite surprised that this isn't the default behavior of ParametricNDSolve. If anyone has more knowledge is there an intuitive reason it doesn't behave in the above manner? Commented Dec 17, 2021 at 16:28
• That ParametricNDSolve(Value) is unable to do this looks reportable to me; I see no obvious reason why it should fail. Commented Dec 17, 2021 at 16:31
• @J.M. thanks! I'll fill out that document! Commented Dec 17, 2021 at 16:35

In this particular case, you can use DSolve

eqns = {v''[x] == 10, v'[a] == 1, v[a] == 1};

soln = DSolve[eqns, v, x][[1]]

(* {v -> Function[{x}, 1 - a + 5 a^2 + x - 10 a x + 5 x^2]} *)


Verifying,

eqns /. soln

(* {True, True, True} *)


Plotting,

Plot3D[Evaluate[v[x] /. soln], {x, 0, 10}, {a, 0, 5},
ColorFunction ->
Function[{x, a, v}, ColorData[97][If[x >= a, 2, 1]]],
PlotPoints -> 75,
MaxRecursion -> 5,
AxesLabel -> (Style[#, 14] & /@ {x, a, v})]


• I was assuming the OP just posted a toy example, but really had a problem with a more complicated RHS. Commented Dec 17, 2021 at 18:51