I want to make a function that takes a function as a parameter and prints an integral with the function inside. I've tried this:
L[f_, a_, b_] := HoldForm[Integrate[f[x], {x, a, b}]]
L[E^-Sqrt[#] &, 0, 1]
But it gives me this:
$$\int_0^1 \left(e^{-\sqrt{\text{#1}}}\text{&}\right)[x] \, dx$$
I want the integrand to look normal, that's all, so I want the variable x to be substituted inside it, but not evaluated any further. Is this possible?
Answer
This works nicely:
L[f_, a_, b_] := HoldForm[Integrate[#, {\[FormalX], a, b}]] &[f[\[FormalX]]]
Note that I used \[FormalX]
to prevent conflicts with the usual x
, which may have had a previous definition. Try L[E^-Sqrt[#] &, 0, 1]
with this definition:
Comments
Post a Comment