The easiest way is to test your integrand f
and see if it evaluates to a numeric value.
Plug in a numerical value like this:
a x /. x -> 0.5
(* 0.5 a *)
As you can see it evaluated to 0.5 a
, which contains a Symbol
and is not a number. In this case, the problem was an undefined parameter. Another common issue is an improper function call:
f[x_, y_] := x Cos[y];
NIntegrate[f[ReIm[Exp[2 Pi I t]]], {t, 0, 1}]
NIntegrate::inumr: The integrand f[{Re[E^(2 I π t)],Im[E^(2 I π t)]}] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,1}}.
(* NIntegrate[f[ReIm[Exp[2 π I t]]], {t, 0, 1}] *)
Test the integrand:
f[ReIm[Exp[2 Pi I t]]] /. t -> 0.5
(* f[{-1., 1.22465*10^-16}] *)
The function f
is called on a List
, not on the individual coordinates, which does not match its definition. As a result, it does not evaluate to a numeric value. (The fix is either to integrate f @@ ReIm[Exp[2 Pi I t]]
or to change the definition to f[{x_, y_}] :=...
, but the fix will depend on each particular case.)
Note I plugged in a machine float 0.5
to test the function, not an exact number such as 1/2
. A machine input should evaluate to a machine number if everything is working. An exact input will evaluate to an exact expression, which may be as complicated as your integrand: it may be hard to tell if the result is numeric, and if not, you may not see the undefined parameters, such as a
in the OP.
It's possible to pick a bad number to plug in that results in a numeric error, such as division by zero. Usually you can try a different number. When it seems hopeless, you can replace NIntegate
by Table
to test many values. This is easily done by copying the input. You should change the iteration to give several floating-point numbers:
Table[a x, {x, 0., 1., 0.1}]
You can also try plotting, but you do not see which parameters, function calls or whatever is causing the trouble:
Plot[a x, {x, 0, 1}]