When I try to integrate a function mapping a vector to a scalar Mathematica "ignores" the function and returns a vector independent of the function.
Here is a minimal example of my problem: I want to integrate the sum over all absolute values in a vector over a 2D unit circle. When I use the Total
function for this, i.e. f1
Mathematica returns a scalar (2.67) that looks reasonable. When I use my f2
function which - as far as I know - should basically implement the Total
function, it does not return a scalar but a vector {0., 0.}
.
f1[x_] := Total[x]
f2[x_] := Apply[Plus, x]
NIntegrate[f1[Abs[x]], x \[Element] Ball[ConstantArray[0, 2]]]
NIntegrate[f2[Abs[x]], x \[Element] Ball[ConstantArray[0, 2]]]
When I directly compare what my f2
function does it looks like it behaves like the f1
function, i.e.
f1[{0.2, 0.3 }] == f2[{0.2, 0.3}]
returns True
.
I am puzzled by the (seemingly) different behavior of Mathematica depending on whether I use the f2
function inside NIntegrate
or outside; now I am looking for an explanation what happens here and how and why I have to modify the f2
function such that it behaves like f1
in my integral.
f1
integrand in anEvaluate
? I have a feeling this is due toNIntegrate
trying to transform the integrand before inserting values forx
but I'm not sure. $\endgroup$f2
withEvaluate
doesn't change the return value - it's still{0., 0.}
. $\endgroup$f2[Abs[x]]
evaluates to symbolically. Tryf2[x_?VectorQ] := Apply[Plus,x]
. $\endgroup$