Documentation of v9 states that ParametricFunction is generated by ParametricNDSolve and ParametricNDSolveValue.

Is there any way of creating ParametricFunction by definition, similar to creating an InterpolatingFunction by Interpolation?

My motivation behind is that for certain parameters, I need solution of ParametricNDSolveValue to be returned and for other parameters I want to use analytical solution to be returner in the same format -ParametricFunction.

  • 1
    $\begingroup$ why don't you just return the analytical solution as a Function[args, Evaluate[analyticalSolution]]? $\endgroup$ – user21 Aug 22 '13 at 12:51
  • $\begingroup$ thanks for idea! I'm going to put example and my answer to it for clarity. $\endgroup$ – Cendo Aug 22 '13 at 13:55

Assume an example function which will switch behaviour depending on c being True or False. This solution is based on comment of @ruebenko.

fun[c_] := Module[{x, a, b, t},
               x''[t] + a x'[t] + b^2 x[t] == 0, 
               x[0] == 1, 
               x'[0] == 0},
               x, {t, 0, 10}, {a, b}],
               Function[{a, b}, 
                Interpolation[{#, #^2} & /@Range[0, 10, 1]
                (*same range of t in InterpolatingFunction as from ParametricNDSolveValue*)]]

Now we call fun with :

fTrue = fun[True]
fFalse = fun[False]
(*Function[{a, b}, Interpolation[({#1, #1^2} &) /@ Range[0, 10, 1]]]*)

We can address both resulting functions like a ParametricFunction and get an InterpolatingFunction:

fTrue[1, 1]
fFalse[1, 1]
(* InterpolatingFunction[{{0.,10.}},<>] *)
(* InterpolatingFunction[{{0,10}},<>] *)

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.