I have a (hopefully small) problem with some numerical integration algorithm, more specifically I want to integrate the imaginary part of a complex valued function, e.g. f[u_]:=Exp[-iuK] with $K\in\mathbb{R}$. As mentioned I am only interested in Im[f], in the example -Sin[u K].
Now if I integrate with Mathematica
NIntegrate[f, {s, Min[roots[[ 1 ]], roots[[ 2 ]]],
Max[roots[[ 1 ]], roots[[ 2 ]]]}, AccuracyGoal->aGoal,
PrecisionGoal->pGoal, WorkingPrecision->wPrecision ];
I get two different results depending on f:
- if I use
-Sin[u K], it returnssomenumber - if I use
Im[f], it returns a list{ somenumber }Those two have to be treated differently and that crashes my program. I have a few questions:
Why does Mathematica sometimes return lists, and sometimes values? How can I distinguish between a list and a value, i.e.
If xyz is a list then
do something
else
do something else
end
Any other ideas how one could avoid these different return "types"? The manual and anything I found hasn't been useful so far.

NIntegrateis returning aListin one case, and a simple value in another. So, what are you using forroots? – rcollyer Mar 01 '12 at 19:34Clear[f]; f[u_] := Exp[-I u]; NIntegrate[Im[f[s]], {s, 0, 1}]works just fine (returning a Real value). – whuber Mar 01 '12 at 21:04