How do I define functionals in Mathematica?

Make sure that you pass the right head/function to W. For example, Sin[Sin] @ x gives Sin[Sin][x], obviously unrecognizable by MMA, not to mention the aftermath evaluation of the integral. So one optional solution can be these

W[Sin[#] + Cos[#] &]
W[Sin @* Sin]

where @* is Composition.


Sin is something that takes an argument---Sin[7] is a number.

In contrast, Sin+Cos is not something that takes an argument! Your functional is trying to evaluate eg. (Sin+Cos)[7] which, without help, it does not understand.

So, you need to turn the argument of W into something that properly takes argument.

You could say

g[x]:= Sin[x]+Cos[x]
W[g]

for example. Or, you can do it anonymously using pure functions (#),

W[Sin[#]+Cos[#]&]

For Sin + Cos you could define SubValues for CirclePlus:

CirclePlus[f_, g_][x] := f[x] + g[x]

Then:

W[Sin ⊕ Cos]

2

Tags:

Functional