I use ParametricNDSolve to return a particular combination of the (vector) variables, at the end of the integration range.

This gives a ParametricFunction with the gory details in the output box, that I would like to hide if possible:

enter image description here

A smaller definite example:

f = ParametricNDSolveValue[{Y'[x] == q Y[x], Y[0] == Table[1, 4], 
  v'[x] == Sin[x], v[0] == 0}, 
 Exp[-v[4]]*Sin[v[4] + 1] Y[4].Y[4], {x, 0, 4}, q];

Then if I ask for f, I get the full description:


enter image description here

Is there a neat way to do this, that will not slow down the evaluation at parameter values?

  • 1
    $\begingroup$ What about ; after ParametricNDSolveValue[[...]? $\endgroup$ – Ulrich Neumann Jun 5 at 14:37
  • $\begingroup$ The function is the output of one function, to then be used later on in my package for finding roots, plotting etc. I know this is a small thing, but people are likely to just use the first function without a semicolon at the end. $\endgroup$ – KraZug Jun 5 at 15:04

You could use a function as the second argument:

func[a_, b_] := Exp[-a] Sin[a+1] b.b
g = ParametricNDSolveValue[
    {Y'[x]==q Y[x], Y[0]==Table[1,4], v'[x]==Sin[x], v[0]==0},
    Unevaluated @ func[v[4],Y[4]],
    {x, 0, 4},

enter image description here

It still works:

f /@ Range[0, 4]
g /@ Range[0, 4]

{0.358834, 1069.67, 3.18864*10^6, 9.5052*10^9, 2.83346*10^13}

{0.358834, 1069.67, 3.18864*10^6, 9.5052*10^9, 2.83346*10^13}

  • $\begingroup$ Thank you. I tried something similar with Hold but that didn't work. $\endgroup$ – KraZug Jun 5 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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