Skip to main content
Tweeted twitter.com/StackMma/status/1115313522701950977
added 379 characters in body
Source Link
Ulrich Neumann
  • 56.8k
  • 2
  • 26
  • 60

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}] 

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?

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}] 
Source Link
Ulrich Neumann
  • 56.8k
  • 2
  • 26
  • 60

How to compile expression which returns a pure function?

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?