I would like to some programming that is very generic. Particularly I am interested in the following:
Let's say I want to write a function
fuu[t_, f_] := Integrate[Exp[a*f[q]], {q, 0, 2*Pi}] /. a -> t
where t
is a real value and f
some function.
Now if I run fuu
multiple times for different values of t
, say 1,2,3 etc. and keep the function f
as Cos
, it will re-run the integration multiple times, which is undesirable.
Storing values is also possible if I write
fuu[t_, f_] := fuu[t, f] = Integrate[Exp[a*f[q]], {q, 0, 2*Pi}] /. a -> t
The problem is that the results from the integration are only stored for specific values of t
then. How do I store it for generic t
but f
fixed as Cos
?
Sure one may argue why not work around this by some other techniques. But the goal in Mathematica is to have effortless code that is still fast - so does anyone have suggestions?
If someone can give me a solution. How can this solution be combined with Let's say that I would want to compile the result from Integrate
to get something even better?