I'm trying to evaluate an integral (numerically would be good enough), but since the integrand contains the same expression several times, I'd like to speed it up by defining a local variable that locally evaluates that expression. Specifically, I write the following
F[σ_] := Integrate[
Module[{a1x = x, a2x = x^σ},
If[.2 a1x >= a2x, a1x, a2x]
],
{x, 0, 1}
]
F[2]
This returns the result
(0.2 + 0.8 x) x
When really, it should be
0.350667
(After all, F is simply integrating $x$ over $[0,.2]$ and $x^2$ over $(.2,1]$.
Why is that? And how can it be fixed?
Edit: In this specific case, NIntegrate gives me the desired result, albeit with a bunch of warnings. In my actual example however, it just runs without end... and then outputs the result with local variables of the type
a1x$12776
So I need to be able to somehow force Mathematica to evaluate the a1x expression FIRST each time it tries to figure out an integrand...