# Question with ParametricNDSolveValue

When solving the following system:

g[a_,b_] := c /. FindRoot[a + b == c, {c, 0}]

pf =
ParametricNDSolveValue[{y''[x] == g[a,b] y[x] Cos[x + y[x]],
y[0] == a, y'[0] == 1}, Integrate[y[s]^2, {s, 0., b}], {x, 0, b}, {a, b}];


Mathematica gives me two error messages, which say:

FindRoot::nlnum: The function value {0. +a+b}is not a list of numbers with dimensions {1} at {c} = {0.}. >>

ReplaceAll::reps: {FindRoot[a+b==c,{c,0}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

How can I fix this issue?

You'd need to preempt symbolic evaluation:

g[a_?NumericQ, b_?NumericQ] := c /. FindRoot[a + b == c, {c, 0}]

pf = ParametricNDSolveValue[{y''[x] == g[a, b] y[x] Cos[x + y[x]],
y[0] == a, y'[0] == 1},
Integrate[y[s]^2, {s, 0., b}], {x, 0, b}, {a, b}]

• it works, thanks a lot. But I do not understand why g[a_?NumericQ, b_?NumericQ] works
– 3c.
Jul 24, 2013 at 16:33
• @user8583, when the command evaluates, before it gets to ParametricNDSolve it evaluates g[a,b] which you do not want. Try your ParametricNDSolveValue[...]//Trace to see what happens.
– user21
Jul 24, 2013 at 16:36
• I get it. thanks
– 3c.
Jul 24, 2013 at 17:39