# How to prevent tiny complex errors in Integrate?

Integrate is adding a tiny imaginary error to an easy result. Why? And how can I stop it?

gauMix[x_, means_, vars_] :=
Total[(E^-(((x - means)^2)/(2*vars)))/Sqrt[2*Pi*vars]]/Length[means];
means = {-7, 7};
vars = {6, 6.5};
f[x_] := gauMix[x, means, vars];
fxx = Integrate[f[x]*(x^2), {x, -Infinity, Infinity}]

(* 55.25 - 3.16199*10^-14 I  *)


If I change vars to {6,6} everything is fine. And NIntegrate hasn't made this error yet, that I've seen. But I want to use Integrate instead of NIntegrate so I can get an exact, analytical answer.

• How tiny? Try Chop. – Kuba Jan 28 '15 at 23:41
• @Kuba I could try that, but I worry about WHY it's adding the error. Is it a symptom of some other error? – Jerry Guern Jan 28 '15 at 23:48
• Not addressing why you see this particular behavior, but if you want an exact analytic answer, you need exact inputs. 6.5 is not an exact number. – chuy Jan 29 '15 at 0:39
• @JerryGuern He means this. Google for "mathematica inexact number". 65/10 would be considered exact. Integrate doesn't play well with inexact numbers. – Szabolcs Jan 29 '15 at 4:38
• Perhaps because these are not full answers? See also, meta.mathematica.stackexchange.com/questions/1457/… – Sjoerd C. de Vries Jan 29 '15 at 16:00

gauMix[x_, means_, vars_] := Total[(E^-(((x - means)^2)/(2*vars)))/Sqrt[2*Pi*vars]]/ Length[means];