Using Mathematica the definition of user functions , which return "pure functions" is quite easy
f[list_] := Function[t, Sin[list[[1]] t] + list[[2]] Cos[t]]
Plot[f[{2, 1}][t], {t, 0, 2 Pi}]
and often very useful. Please note the use of f[liste][time]
with separated argument brackets.
My question:
Is it possible to pre-compile the part f[list]
in such a way that it returns a pure function object?
here a small example to clarify my question:
pg[a_(*liste *)] := Interpolation[{{0, 0}, {.4, a[[1]]}, {.8, a[[2]]}, {1, 1}} , InterpolationOrder -> 1]
defines a polygon with two variable points. pg[a] is a pure function object
which can be used to find the polygon pg[a][x]~=x
opt = NMinimize[Sum[(trapez[{a, b}][x] - x)^2, {x, 0, 1, .2}], {a, b}]
f[list_] := Function[t, Evaluate[Sin[list[[1]] t] + list[[2]] Cos[t]]]; g = f[{2, 1}]; Plot[g[t], {t, 0, 2 Pi}]
$\endgroup$Interpoaltion[data[parameters]]
These parameters are evaluated in a minimization process(involving NDSOlve,NMinimize), which calls the function repeatedly. For performance issues I would like to try a compiled version. $\endgroup$NMinimize
orNDSolve
appear in the code, it is usually not a good idea to compile it. But there might be other ways to speed up your code. $\endgroup$