# Why does Integrate return an unexpected imaginary solution?

When I calculate the value of the following integral using Integrate, I receive an unexpected imaginary solution. I am using Mathematica 11.3.0.

Integrate[
9.257208212146324*^14 Cos[6.0415243338265245 x] Cos[30.207621669132624x]
Sin[42.290670336785674 x] U[5, 0] U[7, 0],
{x, 0, 0.52}
]
(* Out: (1.15009*10^14 - 0.0425289 I) U[5, 0] U[7, 0] *)

• It seems to be on the order of round-off error (relative magnitude ~ \$MachineEpsilon). Commented Jun 12, 2020 at 4:27

## 1 Answer

This is due to precision issues with the floating-point math. Always use exact numbers with exact commands such as Integrate, else it might use numerical methods internally.

integrand =
9.257208212146324*^14 Cos[6.0415243338265245 x]
Cos[30.207621669132624 x] Sin[42.290670336785674 x];
integrand0 = SetPrecision[integrand, Infinity]


 Integrate[integrand0 , {x, 0, 52/100}]


N[%]
(* Out: 1.15009*^14 *)


• Interesting/bizarre: SetPrecision[ Hold@Integrate[ 9.257208212146324*^14 Cos[6.0415243338265245 x] Cos[ 30.207621669132624 x] Sin[42.290670336785674 x] U[5, 0] U[7, 0], {x, 0, 0.52}], 16] Commented Jun 12, 2020 at 4:23
• @MichaelE2 The main issues appears to be U[5, 0] U[7, 0]. When omitted, the integration is performed, although with the strange warning message about the precision of the argument function. Commented Jun 12, 2020 at 18:48
• @bbgodfrey For me the main issue is that the evaluation leaked outside of Hold. I would think that could be considered a bug. Consider SetPrecision[Hold[Sin[1]], 16] in which Sin is not evaluated. Evaluation also leaks if I replace Hold by HoldComplete. Commented Jun 12, 2020 at 21:16
• @MichaelE2 I see your point. Thanks. Commented Jun 12, 2020 at 21:27