0
$\begingroup$

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.

$\endgroup$

closed as off-topic by Szabolcs, m_goldberg, MarcoB, Alex Trounev, eyorble Apr 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.

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

The answer to your questions is no.

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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.