# Create ParametricFunction object without ParametricNDSolve

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.

-
why don't you just return the analytical solution as a Function[args, Evaluate[analyticalSolution]]? – user21 Aug 22 '13 at 12:51
thanks for idea! I'm going to put example and my answer to it for clarity. – 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},
If[c,
ParametricNDSolveValue[{
x''[t] + a x'[t] + b^2 x[t] == 0,
x[0] == 1,
x'[0] == 0},
x, {t, 0, 10}, {a, b}],
(*else*)
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]
(*ParametricFunction[<>]*)
(*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}},<>] *)

-