# Passing a function into another function that integrates the 1st function [closed]

for example I have

a = Sin[t]


and then I have

f[a_] := Integrate[a, {x, 0, pi}]


Will it work?

Will the t in the sine expression be changed to 0 and Pi?

I don't define the 't' as an input to the function. If I run it, it'll probably just integrate the sine, but it didn't put the 0 and the pi to the sin.

I want the 0 and the Pi to be in the sine, but I don't know how to do it because I am still learning the Wolfram Language.

Any help would be appreciated.

## closed as off-topic by Szabolcs, m_goldberg, MarcoB, Alex Trounev, eyorbleApr 14 at 7:23

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, MarcoB, Alex Trounev, eyorble
If this question can be reworded to fit the rules in the help center, please edit the question.

• I'm a little confused about your "will it work" question. Have you tried it? – march Apr 13 at 17:40

But this will work:

a = Sin;
f[func_] := Integrate[func[x], {x, 0, Pi}]
f[a]
f[Cos]


2
0

### Update

The following is added to address concerns raised by the OP in a comment to this answer.

Your function f has been written to expect an argument that can be used as the head of a function call. Sin[x] - Cos[x] is an expression that cannot be used in that manner: Integrate would see (Sin[x] - Cos[x])[x] which is not a valid integrand.

So if you are going to give f an expression, it needs to be converted into a function before it is passed. Here are two ways to do it.

Define a new function that evaluates to the expression.

g[x_] := Sin[x] - Cos[x]
f[g]


2

Convert the expression into a pure function (look up Function in the documentation).

f[Sin[#] - Cos[#] &]


2

• what if I want to have 2 different function ? for example, integrate [ sin[x] - cos [x] ] – Gokturk gokturk Apr 14 at 4:16
• @Gokturkgokturk.I have addressed your concern in an update to my answer. – m_goldberg Apr 14 at 15:30