2
$\begingroup$

Consider this toy example:

f[t_?NumericQ, a_?NumericQ] := t + a

tst = ParametricNDSolveValue[{x'[t] == f[t, a], x[0] == 0}, x, {t, 0, 1}, {a}]

ParametricNDSolveValue::pdvar: Dependent variables {x, f[t, a]} cannot depend on parameters {a}.

As we can see, f is just a black-box function involving both independent variable t and parameter a, but ParametricNDSolveValue/ParametricNDSolveValue has mistakenly parsed it as dependent variable, spit out pdvar warning and failed.

I'm not sure if this should be considered a bug or design mistake. To make this post a question, let me ask: how can I circumvent the issue?

$\endgroup$

1 Answer 1

3
$\begingroup$

I manage to find two work-arounds.

One is to set the DependentVariables option:

f[t_?NumericQ, a_?NumericQ] := t + a

tstfix = ParametricNDSolveValue[{x'[t] == f[t, a], x[0] == 0}, x, {t, 0, 1}, {a}, 
  DependentVariables -> x]

The other is to define the black-box function via SubValues and set the independent variable t as the first argument of the function:

f2[t_?NumericQ][a_?NumericQ] := t + a

tstfix2 = ParametricNDSolveValue[{x'[t] == f2[t][a], x[0] == 0}, x, {t, 0, 1}, {a}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.