NIntegrate::inumr
Examples
Basic Examples (2)
An error occurs because the integrand contains a parameter that does not have a numerical value:
NIntegrate[Cos[c x], {x, 0, 6}]The integral is computed without difficulty if the parameter has a numerical value:
With[{c = 1}, NIntegrate[Cos[c x], {x, 0, 6}]]Here, NIntegrate is used within NMaximize and is evaluated repeatedly without a numerical value for c:
NMaximize[NIntegrate[Sin[c x], {x, 0, π}], c]One possible solution is to use Integrate instead of NIntegrate. This is advantageous because NMaximize can do symbolic processing on its input:
NMaximize[Integrate[Sin[c x], {x, 0, π}], c]If symbolic integration is not possible, an alternative is to restrict the argument type given to NIntegrate with NumericQ by writing a helper function fun:
fun[c_ ? NumericQ] := NIntegrate[Sin[c x], {x, 0, π}]Symbolic input returns unevaluated:
fun[a]fun[1]Now, using NMaximize on fun evaluates without any warnings:
NMaximize[fun[c], c]