This is a question related to the evaluation of a parametric function dependent on a random number of parameters.
Consider a "blackBox" that returns a parametric function dependent on time (t) and, randomly, on N parameters: $\{p_1, ..., p_N\}$. At the outset, we don't know what N is. The only way to measure N is to call the blackBox. If the blackBox is called again, N might change.
How to evaluate the box at $t = 1$, $p_1=1$, $p_2=2$ , ...., $p_N=N$?
For concreteness, consider the following "little-black-box":
littleblackBox := Module[{parameters},
parameters = If[RandomReal[] < 0.5, {p1}, {p1, p2}];
Return[ParametricNDSolveValue[{f'[t] + f[t] == 0,
f[0] == Total[parameters]}, f, {t, 0, 1}, parameters]]
]
It returns a parametric function dependent on time and, randomly, dependent on either one parameter: $\{p_1\}$, or two: $\{p_1, p_2\}$.
Clearly,
Evaluate[littleblackBox[##] &[1][t]] /. t -> 1
or
Evaluate[littleblackBox[##] &[1, 2][t]] /. t -> 1
could fail. On the other hand, one might think that
evaluatelittleBlackBox := Module[{Np, localBox},
localBox = littleblackBox;
Np = Length[localBox[[-2]][[1]]];(*get number of parameters*)
If[ Np == 1, Evaluate[localBox[##] &[1][t]] /. t -> 1 ,
Evaluate[localBox[##] &[1, 2][t]] /. t -> 1]
]
does the work; however, I was able to define this function using as prior knowledge that the little-black-box depends on two parameters at most. This doesn't constitute a satisfactory answer.
Aim: rewrite "evaluatelittleBlackBox" without looking inside the little-black-box!
ParametricFunction[...]
object? Or could it be any type of function-like expression? $\endgroup$1
ton
? $\endgroup$