Consider these two functions which are almost the same:
f[x_] := N@
Evaluate[Integrate[Sin[z]*Cos[x - z], {z, 0, x}]]
g[x_] :=
Evaluate[Integrate[Sin[z]*Cos[x - z], {z, 0, x}]]
The first function has this extra command: N@
f[{1, 2}]
returns:
{{{0.420735, 1.22404}, {0.100612, 0.909297}}}
N@g[{1, 2}]
returns:
{{0.420735, 0.909297}}
and,
N@Integrate[Sin[z]*Cos[1 - z], {z, 0, 1}] = 0.420735
N@Integrate[Sin[z]*Cos[1 - z], {z, 0, 2}] = 1.22404
N@Integrate[Sin[z]*Cos[2 - z], {z, 0, 1}] = 0.100612
N@Integrate[Sin[z]*Cos[2 - z], {z, 0, 2}] = 0.909297
it seems f
uses a combination of 1
and 2
and put each in the x
in Cos
and the upper limit of integral independently.
Does anybody know why it happens?
Table
gives a simpler example without eliminating the issue you raise? $\endgroup$f[x_] := N@Evaluate[Integrate[x - z, {z, 0, x}]]; g[x_] := Evaluate[Integrate[x - z, {z, 0, x}]]
. $\endgroup$Table
does not an effect. I will correct that later. $\endgroup$Integrate[z + {a, b}, {z, {r, s}, {t, u}}]
threads over{{a,b},{r,s},{t,u}}
. More generally, it seems to do so if the the integrand isListable
: i.e., if foo isListable
, thenIntegrate[foo[z, {a, b}], {z, {r, s}, {t, u}}]
threads, not just over{a,b}
, but over{{a,b},{r,s},{t,u}}
$\endgroup$N
except insofar as it preventsEvaluate
from doing anything (becauseEvaluate
is no longer immediately under the:=
). The real reason for the difference is that ing
the integral is pre-evaluated while inf
it is not. $\endgroup$